
<!DOCTYPE HTML>
<html lang="zh-hans" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>Javascript教程 - this 关键字 - 小白AI.易名</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="Javascript教程"><meta name="keywords" content="小白AI.易名,xiaobaiai.net,Javascript,入门,教程,博客">
        <meta name="generator" content="GitBook 3.2.3">
        <meta name="author" content="小白AI.易名">
        
        
    
    <link rel="stylesheet" href="../../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-chapter-fold/chapter-fold.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-back-to-top-button/plugin.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-search-pro/search.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-page-footer-ex/style/plugin.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-search/search.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="prototype.html" />
    
    
    <link rel="prev" href="new.html" />
    

    
        <link rel="shortcut icon" href='../../assets/images/favicon.ico' type="image/x-icon">
    
    
        <link rel="bookmark" href='../../assets/images/favicon.ico' type="image/x-icon">
    
    
        <link rel="apple-touch-icon" href='../../assets/images/apple-touch-icon.png'>
    
    
        
        <link rel="apple-touch-icon" sizes="120x120" href="../../assets/images/apple-touch-icon-120x120.png">
        
        <link rel="apple-touch-icon" sizes="180x180" href="../../assets/images/apple-touch-icon-180x180.png">
        
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="输入并搜索" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../../">
            
                <a href="../../">
            
                    
                    简介
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="../basic/">
            
                <a href="../basic/">
            
                    
                    入门篇
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.2.1" data-path="../basic/introduction.html">
            
                <a href="../basic/introduction.html">
            
                    
                    导论
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.2" data-path="../basic/history.html">
            
                <a href="../basic/history.html">
            
                    
                    历史
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.3" data-path="../basic/grammar.html">
            
                <a href="../basic/grammar.html">
            
                    
                    基本语法
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="../types/">
            
                <a href="../types/">
            
                    
                    数据类型
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.3.1" data-path="../types/general.html">
            
                <a href="../types/general.html">
            
                    
                    概述
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.2" data-path="../types/null-undefined-boolean.html">
            
                <a href="../types/null-undefined-boolean.html">
            
                    
                    null,undefined和布尔值
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.3" data-path="../types/number.html">
            
                <a href="../types/number.html">
            
                    
                    数值
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.4" data-path="../types/string.html">
            
                <a href="../types/string.html">
            
                    
                    字符串
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.5" data-path="../types/object.html">
            
                <a href="../types/object.html">
            
                    
                    对象
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.6" data-path="../types/function.html">
            
                <a href="../types/function.html">
            
                    
                    函数
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.7" data-path="../types/array.html">
            
                <a href="../types/array.html">
            
                    
                    数组
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="../operators/">
            
                <a href="../operators/">
            
                    
                    运算符
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.4.1" data-path="../operators/arithmetic.html">
            
                <a href="../operators/arithmetic.html">
            
                    
                    算术运算符
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.2" data-path="../operators/comparison.html">
            
                <a href="../operators/comparison.html">
            
                    
                    比较运算符
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.3" data-path="../operators/boolean.html">
            
                <a href="../operators/boolean.html">
            
                    
                    布尔运算符
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.4" data-path="../operators/bit.html">
            
                <a href="../operators/bit.html">
            
                    
                    二进制位运算符
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.5" data-path="../operators/priority.html">
            
                <a href="../operators/priority.html">
            
                    
                    其他运算符，运算顺序
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.5" data-path="../features/">
            
                <a href="../features/">
            
                    
                    语法专题
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.5.1" data-path="../features/conversion.html">
            
                <a href="../features/conversion.html">
            
                    
                    数据类型的转换
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.2" data-path="../features/error.html">
            
                <a href="../features/error.html">
            
                    
                    错误处理机制
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.3" data-path="../features/style.html">
            
                <a href="../features/style.html">
            
                    
                    编程风格
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.4" data-path="../features/console.html">
            
                <a href="../features/console.html">
            
                    
                    console 对象与控制台
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.6" data-path="../stdlib/">
            
                <a href="../stdlib/">
            
                    
                    标准库
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.6.1" data-path="../stdlib/object.html">
            
                <a href="../stdlib/object.html">
            
                    
                    Object 对象
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.2" data-path="../stdlib/attributes.html">
            
                <a href="../stdlib/attributes.html">
            
                    
                    属性描述对象
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.3" data-path="../stdlib/array.html">
            
                <a href="../stdlib/array.html">
            
                    
                    Array 对象
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.4" data-path="../stdlib/wrapper.html">
            
                <a href="../stdlib/wrapper.html">
            
                    
                    包装对象
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.5" data-path="../stdlib/boolean.html">
            
                <a href="../stdlib/boolean.html">
            
                    
                    Boolean 对象
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.6" data-path="../stdlib/number.html">
            
                <a href="../stdlib/number.html">
            
                    
                    Number 对象
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.7" data-path="../stdlib/string.html">
            
                <a href="../stdlib/string.html">
            
                    
                    String 对象
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.8" data-path="../stdlib/math.html">
            
                <a href="../stdlib/math.html">
            
                    
                    Math 对象
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.9" data-path="../stdlib/date.html">
            
                <a href="../stdlib/date.html">
            
                    
                    Date 对象
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.10" data-path="../stdlib/regexp.html">
            
                <a href="../stdlib/regexp.html">
            
                    
                    RegExp 对象
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.11" data-path="../stdlib/json.html">
            
                <a href="../stdlib/json.html">
            
                    
                    JSON 对象
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.7" data-path="./">
            
                <a href="./">
            
                    
                    面向对象编程
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.7.1" data-path="new.html">
            
                <a href="new.html">
            
                    
                    实例对象与 New 命令
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="1.7.2" data-path="this.html">
            
                <a href="this.html">
            
                    
                    this 关键字
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.3" data-path="prototype.html">
            
                <a href="prototype.html">
            
                    
                    对象的继承
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.4" data-path="object.html">
            
                <a href="object.html">
            
                    
                    Object 对象的相关方法
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.5" data-path="strict.html">
            
                <a href="strict.html">
            
                    
                    严格模式
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.8" data-path="../async/">
            
                <a href="../async/">
            
                    
                    异步操作
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.8.1" data-path="../async/general.html">
            
                <a href="../async/general.html">
            
                    
                    概述
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.2" data-path="../async/timer.html">
            
                <a href="../async/timer.html">
            
                    
                    定时器
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.3" data-path="../async/promise.html">
            
                <a href="../async/promise.html">
            
                    
                    Promise 对象
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.9" data-path="../dom/">
            
                <a href="../dom/">
            
                    
                    DOM
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.9.1" data-path="../dom/general.html">
            
                <a href="../dom/general.html">
            
                    
                    概述
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.2" data-path="../dom/node.html">
            
                <a href="../dom/node.html">
            
                    
                    Node 接口
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.3" data-path="../dom/nodelist.html">
            
                <a href="../dom/nodelist.html">
            
                    
                    NodeList 接口，HTMLCollection 接口
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.4" data-path="../dom/parentnode.html">
            
                <a href="../dom/parentnode.html">
            
                    
                    ParentNode 接口，ChildNode 接口
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.5" data-path="../dom/document.html">
            
                <a href="../dom/document.html">
            
                    
                    Document 节点
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.6" data-path="../dom/element.html">
            
                <a href="../dom/element.html">
            
                    
                    Element 节点
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.7" data-path="../dom/attributes.html">
            
                <a href="../dom/attributes.html">
            
                    
                    属性的操作
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.8" data-path="../dom/text.html">
            
                <a href="../dom/text.html">
            
                    
                    Text 节点和 DocumentFragment 节点
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.9" data-path="../dom/css.html">
            
                <a href="../dom/css.html">
            
                    
                    CSS 操作
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.10" data-path="../dom/mutationobserver.html">
            
                <a href="../dom/mutationobserver.html">
            
                    
                    Mutation Observer API
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.10" data-path="../events/">
            
                <a href="../events/">
            
                    
                    事件
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.10.1" data-path="../events/eventtarget.html">
            
                <a href="../events/eventtarget.html">
            
                    
                    EventTarget 接口
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.2" data-path="../events/model.html">
            
                <a href="../events/model.html">
            
                    
                    事件模型
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.3" data-path="../events/event.html">
            
                <a href="../events/event.html">
            
                    
                    Event 对象
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.4" data-path="../events/mouse.html">
            
                <a href="../events/mouse.html">
            
                    
                    鼠标事件
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.5" data-path="../events/keyboard.html">
            
                <a href="../events/keyboard.html">
            
                    
                    键盘事件
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.6" data-path="../events/progress.html">
            
                <a href="../events/progress.html">
            
                    
                    进度事件
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.7" data-path="../events/form.html">
            
                <a href="../events/form.html">
            
                    
                    表单事件
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.8" data-path="../events/touch.html">
            
                <a href="../events/touch.html">
            
                    
                    触摸事件
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.9" data-path="../events/drag.html">
            
                <a href="../events/drag.html">
            
                    
                    拖拉事件
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.10" data-path="../events/common.html">
            
                <a href="../events/common.html">
            
                    
                    其他常见事件
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.11" data-path="../events/globaleventhandlers.html">
            
                <a href="../events/globaleventhandlers.html">
            
                    
                    GlobalEventHandlers 接口
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.11" data-path="../bom/">
            
                <a href="../bom/">
            
                    
                    浏览器模型
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.11.1" data-path="../bom/engine.html">
            
                <a href="../bom/engine.html">
            
                    
                    浏览器模型概述
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.2" data-path="../bom/window.html">
            
                <a href="../bom/window.html">
            
                    
                    window 对象
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.3" data-path="../bom/navigator.html">
            
                <a href="../bom/navigator.html">
            
                    
                    Navigatror 对象，Screen 对象
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.4" data-path="../bom/cookie.html">
            
                <a href="../bom/cookie.html">
            
                    
                    Cookie
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.5" data-path="../bom/xmlhttprequest.html">
            
                <a href="../bom/xmlhttprequest.html">
            
                    
                    XMLHttpRequest 对象
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.6" data-path="../bom/same-origin.html">
            
                <a href="../bom/same-origin.html">
            
                    
                    同源限制
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.7" data-path="../bom/cors.html">
            
                <a href="../bom/cors.html">
            
                    
                    CORS 通信
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.8" data-path="../bom/storage.html">
            
                <a href="../bom/storage.html">
            
                    
                    Storage 接口
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.9" data-path="../bom/history.html">
            
                <a href="../bom/history.html">
            
                    
                    History 对象
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.10" data-path="../bom/location.html">
            
                <a href="../bom/location.html">
            
                    
                    Location对象，URL对象，URLSearchParams 对象
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.11" data-path="../bom/arraybuffer.html">
            
                <a href="../bom/arraybuffer.html">
            
                    
                    ArrayBuffer 对象，Blob对象
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.12" data-path="../bom/file.html">
            
                <a href="../bom/file.html">
            
                    
                    File 对象，FileList 对象，FileReader 对象
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.13" data-path="../bom/form.html">
            
                <a href="../bom/form.html">
            
                    
                    表单，FormData 对象
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.14" data-path="../bom/indexeddb.html">
            
                <a href="../bom/indexeddb.html">
            
                    
                    IndexedDB API
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.15" data-path="../bom/webworker.html">
            
                <a href="../bom/webworker.html">
            
                    
                    web worker
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.12" data-path="../elements/">
            
                <a href="../elements/">
            
                    
                    附录:网页元素接口
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.12.1" data-path="../elements/a.html">
            
                <a href="../elements/a.html">
            
                    
                    a超链接
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.2" data-path="../elements/image.html">
            
                <a href="../elements/image.html">
            
                    
                    image图片
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.3" data-path="../elements/form.html">
            
                <a href="../elements/form.html">
            
                    
                    form表单
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.4" data-path="../elements/input.html">
            
                <a href="../elements/input.html">
            
                    
                    input文本框
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.5" data-path="../elements/button.html">
            
                <a href="../elements/button.html">
            
                    
                    button按钮
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.6" data-path="../elements/option.html">
            
                <a href="../elements/option.html">
            
                    
                    option选项
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.7" data-path="../elements/video.html">
            
                <a href="../elements/video.html">
            
                    
                    video,audio音视频
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="_blank" rel="nofollow" class="gitbook-link">
            本书使用 GitBook 发布
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="../.." >this 关键字</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <h1 id="this-&#x5173;&#x952E;&#x5B57;">this &#x5173;&#x952E;&#x5B57;</h1>
<h2 id="&#x6DB5;&#x4E49;">&#x6DB5;&#x4E49;</h2>
<p><code>this</code>&#x5173;&#x952E;&#x5B57;&#x662F;&#x4E00;&#x4E2A;&#x975E;&#x5E38;&#x91CD;&#x8981;&#x7684;&#x8BED;&#x6CD5;&#x70B9;&#x3002;&#x6BEB;&#x4E0D;&#x5938;&#x5F20;&#x5730;&#x8BF4;&#xFF0C;&#x4E0D;&#x7406;&#x89E3;&#x5B83;&#x7684;&#x542B;&#x4E49;&#xFF0C;&#x5927;&#x90E8;&#x5206;&#x5F00;&#x53D1;&#x4EFB;&#x52A1;&#x90FD;&#x65E0;&#x6CD5;&#x5B8C;&#x6210;&#x3002;</p>
<p>&#x524D;&#x4E00;&#x7AE0;&#x5DF2;&#x7ECF;&#x63D0;&#x5230;&#xFF0C;<code>this</code>&#x53EF;&#x4EE5;&#x7528;&#x5728;&#x6784;&#x9020;&#x51FD;&#x6570;&#x4E4B;&#x4E2D;&#xFF0C;&#x8868;&#x793A;&#x5B9E;&#x4F8B;&#x5BF9;&#x8C61;&#x3002;&#x9664;&#x6B64;&#x4E4B;&#x5916;&#xFF0C;<code>this</code>&#x8FD8;&#x53EF;&#x4EE5;&#x7528;&#x5728;&#x522B;&#x7684;&#x573A;&#x5408;&#x3002;&#x4F46;&#x4E0D;&#x7BA1;&#x662F;&#x4EC0;&#x4E48;&#x573A;&#x5408;&#xFF0C;<code>this</code>&#x90FD;&#x6709;&#x4E00;&#x4E2A;&#x5171;&#x540C;&#x70B9;&#xFF1A;&#x5B83;&#x603B;&#x662F;&#x8FD4;&#x56DE;&#x4E00;&#x4E2A;&#x5BF9;&#x8C61;&#x3002;</p>
<p>&#x7B80;&#x5355;&#x8BF4;&#xFF0C;<code>this</code>&#x5C31;&#x662F;&#x5C5E;&#x6027;&#x6216;&#x65B9;&#x6CD5;&#x201C;&#x5F53;&#x524D;&#x201D;&#x6240;&#x5728;&#x7684;&#x5BF9;&#x8C61;&#x3002;</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">this</span>.property
</code></pre>
<p>&#x4E0A;&#x9762;&#x4EE3;&#x7801;&#x4E2D;&#xFF0C;<code>this</code>&#x5C31;&#x4EE3;&#x8868;<code>property</code>&#x5C5E;&#x6027;&#x5F53;&#x524D;&#x6240;&#x5728;&#x7684;&#x5BF9;&#x8C61;&#x3002;</p>
<p>&#x4E0B;&#x9762;&#x662F;&#x4E00;&#x4E2A;&#x5B9E;&#x9645;&#x7684;&#x4F8B;&#x5B50;&#x3002;</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> person = {
  name: <span class="hljs-string">&apos;&#x5F20;&#x4E09;&apos;</span>,
  describe: <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) </span>{
    <span class="hljs-keyword">return</span> <span class="hljs-string">&apos;&#x59D3;&#x540D;&#xFF1A;&apos;</span>+ <span class="hljs-keyword">this</span>.name;
  }
};

person.describe()
<span class="hljs-comment">// &quot;&#x59D3;&#x540D;&#xFF1A;&#x5F20;&#x4E09;&quot;</span>
</code></pre>
<p>&#x4E0A;&#x9762;&#x4EE3;&#x7801;&#x4E2D;&#xFF0C;<code>this.name</code>&#x8868;&#x793A;<code>name</code>&#x5C5E;&#x6027;&#x6240;&#x5728;&#x7684;&#x90A3;&#x4E2A;&#x5BF9;&#x8C61;&#x3002;&#x7531;&#x4E8E;<code>this.name</code>&#x662F;&#x5728;<code>describe</code>&#x65B9;&#x6CD5;&#x4E2D;&#x8C03;&#x7528;&#xFF0C;&#x800C;<code>describe</code>&#x65B9;&#x6CD5;&#x6240;&#x5728;&#x7684;&#x5F53;&#x524D;&#x5BF9;&#x8C61;&#x662F;<code>person</code>&#xFF0C;&#x56E0;&#x6B64;<code>this</code>&#x6307;&#x5411;<code>person</code>&#xFF0C;<code>this.name</code>&#x5C31;&#x662F;<code>person.name</code>&#x3002;</p>
<p>&#x7531;&#x4E8E;&#x5BF9;&#x8C61;&#x7684;&#x5C5E;&#x6027;&#x53EF;&#x4EE5;&#x8D4B;&#x7ED9;&#x53E6;&#x4E00;&#x4E2A;&#x5BF9;&#x8C61;&#xFF0C;&#x6240;&#x4EE5;&#x5C5E;&#x6027;&#x6240;&#x5728;&#x7684;&#x5F53;&#x524D;&#x5BF9;&#x8C61;&#x662F;&#x53EF;&#x53D8;&#x7684;&#xFF0C;&#x5373;<code>this</code>&#x7684;&#x6307;&#x5411;&#x662F;&#x53EF;&#x53D8;&#x7684;&#x3002;</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> A = {
  name: <span class="hljs-string">&apos;&#x5F20;&#x4E09;&apos;</span>,
  describe: <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) </span>{
    <span class="hljs-keyword">return</span> <span class="hljs-string">&apos;&#x59D3;&#x540D;&#xFF1A;&apos;</span>+ <span class="hljs-keyword">this</span>.name;
  }
};

<span class="hljs-keyword">var</span> B = {
  name: <span class="hljs-string">&apos;&#x674E;&#x56DB;&apos;</span>
};

B.describe = A.describe;
B.describe()
<span class="hljs-comment">// &quot;&#x59D3;&#x540D;&#xFF1A;&#x674E;&#x56DB;&quot;</span>
</code></pre>
<p>&#x4E0A;&#x9762;&#x4EE3;&#x7801;&#x4E2D;&#xFF0C;<code>A.describe</code>&#x5C5E;&#x6027;&#x88AB;&#x8D4B;&#x7ED9;<code>B</code>&#xFF0C;&#x4E8E;&#x662F;<code>B.describe</code>&#x5C31;&#x8868;&#x793A;<code>describe</code>&#x65B9;&#x6CD5;&#x6240;&#x5728;&#x7684;&#x5F53;&#x524D;&#x5BF9;&#x8C61;&#x662F;<code>B</code>&#xFF0C;&#x6240;&#x4EE5;<code>this.name</code>&#x5C31;&#x6307;&#x5411;<code>B.name</code>&#x3002;</p>
<p>&#x7A0D;&#x7A0D;&#x91CD;&#x6784;&#x8FD9;&#x4E2A;&#x4F8B;&#x5B50;&#xFF0C;<code>this</code>&#x7684;&#x52A8;&#x6001;&#x6307;&#x5411;&#x5C31;&#x80FD;&#x770B;&#x5F97;&#x66F4;&#x6E05;&#x695A;&#x3002;</p>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">f</span>(<span class="hljs-params"></span>) </span>{
  <span class="hljs-keyword">return</span> <span class="hljs-string">&apos;&#x59D3;&#x540D;&#xFF1A;&apos;</span>+ <span class="hljs-keyword">this</span>.name;
}

<span class="hljs-keyword">var</span> A = {
  name: <span class="hljs-string">&apos;&#x5F20;&#x4E09;&apos;</span>,
  describe: f
};

<span class="hljs-keyword">var</span> B = {
  name: <span class="hljs-string">&apos;&#x674E;&#x56DB;&apos;</span>,
  describe: f
};

A.describe() <span class="hljs-comment">// &quot;&#x59D3;&#x540D;&#xFF1A;&#x5F20;&#x4E09;&quot;</span>
B.describe() <span class="hljs-comment">// &quot;&#x59D3;&#x540D;&#xFF1A;&#x674E;&#x56DB;&quot;</span>
</code></pre>
<p>&#x4E0A;&#x9762;&#x4EE3;&#x7801;&#x4E2D;&#xFF0C;&#x51FD;&#x6570;<code>f</code>&#x5185;&#x90E8;&#x4F7F;&#x7528;&#x4E86;<code>this</code>&#x5173;&#x952E;&#x5B57;&#xFF0C;&#x968F;&#x7740;<code>f</code>&#x6240;&#x5728;&#x7684;&#x5BF9;&#x8C61;&#x4E0D;&#x540C;&#xFF0C;<code>this</code>&#x7684;&#x6307;&#x5411;&#x4E5F;&#x4E0D;&#x540C;&#x3002;</p>
<p>&#x53EA;&#x8981;&#x51FD;&#x6570;&#x88AB;&#x8D4B;&#x7ED9;&#x53E6;&#x4E00;&#x4E2A;&#x53D8;&#x91CF;&#xFF0C;<code>this</code>&#x7684;&#x6307;&#x5411;&#x5C31;&#x4F1A;&#x53D8;&#x3002;</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> A = {
  name: <span class="hljs-string">&apos;&#x5F20;&#x4E09;&apos;</span>,
  describe: <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) </span>{
    <span class="hljs-keyword">return</span> <span class="hljs-string">&apos;&#x59D3;&#x540D;&#xFF1A;&apos;</span>+ <span class="hljs-keyword">this</span>.name;
  }
};

<span class="hljs-keyword">var</span> name = <span class="hljs-string">&apos;&#x674E;&#x56DB;&apos;</span>;
<span class="hljs-keyword">var</span> f = A.describe;
f() <span class="hljs-comment">// &quot;&#x59D3;&#x540D;&#xFF1A;&#x674E;&#x56DB;&quot;</span>
</code></pre>
<p>&#x4E0A;&#x9762;&#x4EE3;&#x7801;&#x4E2D;&#xFF0C;<code>A.describe</code>&#x88AB;&#x8D4B;&#x503C;&#x7ED9;&#x53D8;&#x91CF;<code>f</code>&#xFF0C;&#x5185;&#x90E8;&#x7684;<code>this</code>&#x5C31;&#x4F1A;&#x6307;&#x5411;<code>f</code>&#x8FD0;&#x884C;&#x65F6;&#x6240;&#x5728;&#x7684;&#x5BF9;&#x8C61;&#xFF08;&#x672C;&#x4F8B;&#x662F;&#x9876;&#x5C42;&#x5BF9;&#x8C61;&#xFF09;&#x3002;</p>
<p>&#x518D;&#x770B;&#x4E00;&#x4E2A;&#x7F51;&#x9875;&#x7F16;&#x7A0B;&#x7684;&#x4F8B;&#x5B50;&#x3002;</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">type</span>=<span class="hljs-string">&quot;text&quot;</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;age&quot;</span> <span class="hljs-attr">size</span>=<span class="hljs-string">3</span> <span class="hljs-attr">onChange</span>=<span class="hljs-string">&quot;validate(this, 18, 99);&quot;</span>&gt;</span>

<span class="hljs-tag">&lt;<span class="hljs-name">script</span>&gt;</span><span class="javascript">
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">validate</span>(<span class="hljs-params">obj, lowval, hival</span>)</span>{
  <span class="hljs-keyword">if</span> ((obj.value &lt; lowval) || (obj.value &gt; hival))
    <span class="hljs-built_in">console</span>.log(<span class="hljs-string">&apos;Invalid Value!&apos;</span>);
}
</span><span class="hljs-tag">&lt;/<span class="hljs-name">script</span>&gt;</span>
</code></pre>
<p>&#x4E0A;&#x9762;&#x4EE3;&#x7801;&#x662F;&#x4E00;&#x4E2A;&#x6587;&#x672C;&#x8F93;&#x5165;&#x6846;&#xFF0C;&#x6BCF;&#x5F53;&#x7528;&#x6237;&#x8F93;&#x5165;&#x4E00;&#x4E2A;&#x503C;&#xFF0C;&#x5C31;&#x4F1A;&#x8C03;&#x7528;<code>onChange</code>&#x56DE;&#x8C03;&#x51FD;&#x6570;&#xFF0C;&#x9A8C;&#x8BC1;&#x8FD9;&#x4E2A;&#x503C;&#x662F;&#x5426;&#x5728;&#x6307;&#x5B9A;&#x8303;&#x56F4;&#x3002;&#x6D4F;&#x89C8;&#x5668;&#x4F1A;&#x5411;&#x56DE;&#x8C03;&#x51FD;&#x6570;&#x4F20;&#x5165;&#x5F53;&#x524D;&#x5BF9;&#x8C61;&#xFF0C;&#x56E0;&#x6B64;<code>this</code>&#x5C31;&#x4EE3;&#x8868;&#x4F20;&#x5165;&#x5F53;&#x524D;&#x5BF9;&#x8C61;&#xFF08;&#x5373;&#x6587;&#x672C;&#x6846;&#xFF09;&#xFF0C;&#x7136;&#x540E;&#x5C31;&#x53EF;&#x4EE5;&#x4ECE;<code>this.value</code>&#x4E0A;&#x9762;&#x8BFB;&#x5230;&#x7528;&#x6237;&#x7684;&#x8F93;&#x5165;&#x503C;&#x3002;</p>
<p>&#x603B;&#x7ED3;&#x4E00;&#x4E0B;&#xFF0C;JavaScript &#x8BED;&#x8A00;&#x4E4B;&#x4E2D;&#xFF0C;&#x4E00;&#x5207;&#x7686;&#x5BF9;&#x8C61;&#xFF0C;&#x8FD0;&#x884C;&#x73AF;&#x5883;&#x4E5F;&#x662F;&#x5BF9;&#x8C61;&#xFF0C;&#x6240;&#x4EE5;&#x51FD;&#x6570;&#x90FD;&#x662F;&#x5728;&#x67D0;&#x4E2A;&#x5BF9;&#x8C61;&#x4E4B;&#x4E2D;&#x8FD0;&#x884C;&#xFF0C;<code>this</code>&#x5C31;&#x662F;&#x51FD;&#x6570;&#x8FD0;&#x884C;&#x65F6;&#x6240;&#x5728;&#x7684;&#x5BF9;&#x8C61;&#xFF08;&#x73AF;&#x5883;&#xFF09;&#x3002;&#x8FD9;&#x672C;&#x6765;&#x5E76;&#x4E0D;&#x4F1A;&#x8BA9;&#x7528;&#x6237;&#x7CCA;&#x6D82;&#xFF0C;&#x4F46;&#x662F; JavaScript &#x652F;&#x6301;&#x8FD0;&#x884C;&#x73AF;&#x5883;&#x52A8;&#x6001;&#x5207;&#x6362;&#xFF0C;&#x4E5F;&#x5C31;&#x662F;&#x8BF4;&#xFF0C;<code>this</code>&#x7684;&#x6307;&#x5411;&#x662F;&#x52A8;&#x6001;&#x7684;&#xFF0C;&#x6CA1;&#x6709;&#x529E;&#x6CD5;&#x4E8B;&#x5148;&#x786E;&#x5B9A;&#x5230;&#x5E95;&#x6307;&#x5411;&#x54EA;&#x4E2A;&#x5BF9;&#x8C61;&#xFF0C;&#x8FD9;&#x624D;&#x662F;&#x6700;&#x8BA9;&#x521D;&#x5B66;&#x8005;&#x611F;&#x5230;&#x56F0;&#x60D1;&#x7684;&#x5730;&#x65B9;&#x3002;</p>
<h2 id="&#x5B9E;&#x8D28;">&#x5B9E;&#x8D28;</h2>
<p>JavaScript &#x8BED;&#x8A00;&#x4E4B;&#x6240;&#x4EE5;&#x6709; this &#x7684;&#x8BBE;&#x8BA1;&#xFF0C;&#x8DDF;&#x5185;&#x5B58;&#x91CC;&#x9762;&#x7684;&#x6570;&#x636E;&#x7ED3;&#x6784;&#x6709;&#x5173;&#x7CFB;&#x3002;</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> obj = { foo:  <span class="hljs-number">5</span> };
</code></pre>
<p>&#x4E0A;&#x9762;&#x7684;&#x4EE3;&#x7801;&#x5C06;&#x4E00;&#x4E2A;&#x5BF9;&#x8C61;&#x8D4B;&#x503C;&#x7ED9;&#x53D8;&#x91CF;<code>obj</code>&#x3002;JavaScript &#x5F15;&#x64CE;&#x4F1A;&#x5148;&#x5728;&#x5185;&#x5B58;&#x91CC;&#x9762;&#xFF0C;&#x751F;&#x6210;&#x4E00;&#x4E2A;&#x5BF9;&#x8C61;<code>{ foo: 5 }</code>&#xFF0C;&#x7136;&#x540E;&#x628A;&#x8FD9;&#x4E2A;&#x5BF9;&#x8C61;&#x7684;&#x5185;&#x5B58;&#x5730;&#x5740;&#x8D4B;&#x503C;&#x7ED9;&#x53D8;&#x91CF;<code>obj</code>&#x3002;&#x4E5F;&#x5C31;&#x662F;&#x8BF4;&#xFF0C;&#x53D8;&#x91CF;<code>obj</code>&#x662F;&#x4E00;&#x4E2A;&#x5730;&#x5740;&#xFF08;reference&#xFF09;&#x3002;&#x540E;&#x9762;&#x5982;&#x679C;&#x8981;&#x8BFB;&#x53D6;<code>obj.foo</code>&#xFF0C;&#x5F15;&#x64CE;&#x5148;&#x4ECE;<code>obj</code>&#x62FF;&#x5230;&#x5185;&#x5B58;&#x5730;&#x5740;&#xFF0C;&#x7136;&#x540E;&#x518D;&#x4ECE;&#x8BE5;&#x5730;&#x5740;&#x8BFB;&#x51FA;&#x539F;&#x59CB;&#x7684;&#x5BF9;&#x8C61;&#xFF0C;&#x8FD4;&#x56DE;&#x5B83;&#x7684;<code>foo</code>&#x5C5E;&#x6027;&#x3002;</p>
<p>&#x539F;&#x59CB;&#x7684;&#x5BF9;&#x8C61;&#x4EE5;&#x5B57;&#x5178;&#x7ED3;&#x6784;&#x4FDD;&#x5B58;&#xFF0C;&#x6BCF;&#x4E00;&#x4E2A;&#x5C5E;&#x6027;&#x540D;&#x90FD;&#x5BF9;&#x5E94;&#x4E00;&#x4E2A;&#x5C5E;&#x6027;&#x63CF;&#x8FF0;&#x5BF9;&#x8C61;&#x3002;&#x4E3E;&#x4F8B;&#x6765;&#x8BF4;&#xFF0C;&#x4E0A;&#x9762;&#x4F8B;&#x5B50;&#x7684;<code>foo</code>&#x5C5E;&#x6027;&#xFF0C;&#x5B9E;&#x9645;&#x4E0A;&#x662F;&#x4EE5;&#x4E0B;&#x9762;&#x7684;&#x5F62;&#x5F0F;&#x4FDD;&#x5B58;&#x7684;&#x3002;</p>
<pre><code class="lang-javascript">{
  foo: {
    [[value]]: <span class="hljs-number">5</span>
    [[writable]]: <span class="hljs-literal">true</span>
    [[enumerable]]: <span class="hljs-literal">true</span>
    [[configurable]]: <span class="hljs-literal">true</span>
  }
}
</code></pre>
<p>&#x6CE8;&#x610F;&#xFF0C;<code>foo</code>&#x5C5E;&#x6027;&#x7684;&#x503C;&#x4FDD;&#x5B58;&#x5728;&#x5C5E;&#x6027;&#x63CF;&#x8FF0;&#x5BF9;&#x8C61;&#x7684;<code>value</code>&#x5C5E;&#x6027;&#x91CC;&#x9762;&#x3002;</p>
<p>&#x8FD9;&#x6837;&#x7684;&#x7ED3;&#x6784;&#x662F;&#x5F88;&#x6E05;&#x6670;&#x7684;&#xFF0C;&#x95EE;&#x9898;&#x5728;&#x4E8E;&#x5C5E;&#x6027;&#x7684;&#x503C;&#x53EF;&#x80FD;&#x662F;&#x4E00;&#x4E2A;&#x51FD;&#x6570;&#x3002;</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> obj = { foo: <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) </span>{} };
</code></pre>
<p>&#x8FD9;&#x65F6;&#xFF0C;&#x5F15;&#x64CE;&#x4F1A;&#x5C06;&#x51FD;&#x6570;&#x5355;&#x72EC;&#x4FDD;&#x5B58;&#x5728;&#x5185;&#x5B58;&#x4E2D;&#xFF0C;&#x7136;&#x540E;&#x518D;&#x5C06;&#x51FD;&#x6570;&#x7684;&#x5730;&#x5740;&#x8D4B;&#x503C;&#x7ED9;<code>foo</code>&#x5C5E;&#x6027;&#x7684;<code>value</code>&#x5C5E;&#x6027;&#x3002;</p>
<pre><code class="lang-javascript">{
  foo: {
    [[value]]: &#x51FD;&#x6570;&#x7684;&#x5730;&#x5740;
    ...
  }
}
</code></pre>
<p>&#x7531;&#x4E8E;&#x51FD;&#x6570;&#x662F;&#x4E00;&#x4E2A;&#x5355;&#x72EC;&#x7684;&#x503C;&#xFF0C;&#x6240;&#x4EE5;&#x5B83;&#x53EF;&#x4EE5;&#x5728;&#x4E0D;&#x540C;&#x7684;&#x73AF;&#x5883;&#xFF08;&#x4E0A;&#x4E0B;&#x6587;&#xFF09;&#x6267;&#x884C;&#x3002;</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> f = <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) </span>{};
<span class="hljs-keyword">var</span> obj = { f: f };

<span class="hljs-comment">// &#x5355;&#x72EC;&#x6267;&#x884C;</span>
f()

<span class="hljs-comment">// obj &#x73AF;&#x5883;&#x6267;&#x884C;</span>
obj.f()
</code></pre>
<p>JavaScript &#x5141;&#x8BB8;&#x5728;&#x51FD;&#x6570;&#x4F53;&#x5185;&#x90E8;&#xFF0C;&#x5F15;&#x7528;&#x5F53;&#x524D;&#x73AF;&#x5883;&#x7684;&#x5176;&#x4ED6;&#x53D8;&#x91CF;&#x3002;</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> f = <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) </span>{
  <span class="hljs-built_in">console</span>.log(x);
};
</code></pre>
<p>&#x4E0A;&#x9762;&#x4EE3;&#x7801;&#x4E2D;&#xFF0C;&#x51FD;&#x6570;&#x4F53;&#x91CC;&#x9762;&#x4F7F;&#x7528;&#x4E86;&#x53D8;&#x91CF;<code>x</code>&#x3002;&#x8BE5;&#x53D8;&#x91CF;&#x7531;&#x8FD0;&#x884C;&#x73AF;&#x5883;&#x63D0;&#x4F9B;&#x3002;</p>
<p>&#x73B0;&#x5728;&#x95EE;&#x9898;&#x5C31;&#x6765;&#x4E86;&#xFF0C;&#x7531;&#x4E8E;&#x51FD;&#x6570;&#x53EF;&#x4EE5;&#x5728;&#x4E0D;&#x540C;&#x7684;&#x8FD0;&#x884C;&#x73AF;&#x5883;&#x6267;&#x884C;&#xFF0C;&#x6240;&#x4EE5;&#x9700;&#x8981;&#x6709;&#x4E00;&#x79CD;&#x673A;&#x5236;&#xFF0C;&#x80FD;&#x591F;&#x5728;&#x51FD;&#x6570;&#x4F53;&#x5185;&#x90E8;&#x83B7;&#x5F97;&#x5F53;&#x524D;&#x7684;&#x8FD0;&#x884C;&#x73AF;&#x5883;&#xFF08;context&#xFF09;&#x3002;&#x6240;&#x4EE5;&#xFF0C;<code>this</code>&#x5C31;&#x51FA;&#x73B0;&#x4E86;&#xFF0C;&#x5B83;&#x7684;&#x8BBE;&#x8BA1;&#x76EE;&#x7684;&#x5C31;&#x662F;&#x5728;&#x51FD;&#x6570;&#x4F53;&#x5185;&#x90E8;&#xFF0C;&#x6307;&#x4EE3;&#x51FD;&#x6570;&#x5F53;&#x524D;&#x7684;&#x8FD0;&#x884C;&#x73AF;&#x5883;&#x3002;</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> f = <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) </span>{
  <span class="hljs-built_in">console</span>.log(<span class="hljs-keyword">this</span>.x);
}
</code></pre>
<p>&#x4E0A;&#x9762;&#x4EE3;&#x7801;&#x4E2D;&#xFF0C;&#x51FD;&#x6570;&#x4F53;&#x91CC;&#x9762;&#x7684;<code>this.x</code>&#x5C31;&#x662F;&#x6307;&#x5F53;&#x524D;&#x8FD0;&#x884C;&#x73AF;&#x5883;&#x7684;<code>x</code>&#x3002;</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> f = <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) </span>{
  <span class="hljs-built_in">console</span>.log(<span class="hljs-keyword">this</span>.x);
}

<span class="hljs-keyword">var</span> x = <span class="hljs-number">1</span>;
<span class="hljs-keyword">var</span> obj = {
  f: f,
  x: <span class="hljs-number">2</span>,
};

<span class="hljs-comment">// &#x5355;&#x72EC;&#x6267;&#x884C;</span>
f() <span class="hljs-comment">// 1</span>

<span class="hljs-comment">// obj &#x73AF;&#x5883;&#x6267;&#x884C;</span>
obj.f() <span class="hljs-comment">// 2</span>
</code></pre>
<p>&#x4E0A;&#x9762;&#x4EE3;&#x7801;&#x4E2D;&#xFF0C;&#x51FD;&#x6570;<code>f</code>&#x5728;&#x5168;&#x5C40;&#x73AF;&#x5883;&#x6267;&#x884C;&#xFF0C;<code>this.x</code>&#x6307;&#x5411;&#x5168;&#x5C40;&#x73AF;&#x5883;&#x7684;<code>x</code>&#xFF1B;&#x5728;<code>obj</code>&#x73AF;&#x5883;&#x6267;&#x884C;&#xFF0C;<code>this.x</code>&#x6307;&#x5411;<code>obj.x</code>&#x3002;</p>
<h2 id="&#x4F7F;&#x7528;&#x573A;&#x5408;">&#x4F7F;&#x7528;&#x573A;&#x5408;</h2>
<p><code>this</code>&#x4E3B;&#x8981;&#x6709;&#x4EE5;&#x4E0B;&#x51E0;&#x4E2A;&#x4F7F;&#x7528;&#x573A;&#x5408;&#x3002;</p>
<p><strong>&#xFF08;1&#xFF09;&#x5168;&#x5C40;&#x73AF;&#x5883;</strong></p>
<p>&#x5168;&#x5C40;&#x73AF;&#x5883;&#x4F7F;&#x7528;<code>this</code>&#xFF0C;&#x5B83;&#x6307;&#x7684;&#x5C31;&#x662F;&#x9876;&#x5C42;&#x5BF9;&#x8C61;<code>window</code>&#x3002;</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">this</span> === <span class="hljs-built_in">window</span> <span class="hljs-comment">// true</span>

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">f</span>(<span class="hljs-params"></span>) </span>{
  <span class="hljs-built_in">console</span>.log(<span class="hljs-keyword">this</span> === <span class="hljs-built_in">window</span>);
}
f() <span class="hljs-comment">// true</span>
</code></pre>
<p>&#x4E0A;&#x9762;&#x4EE3;&#x7801;&#x8BF4;&#x660E;&#xFF0C;&#x4E0D;&#x7BA1;&#x662F;&#x4E0D;&#x662F;&#x5728;&#x51FD;&#x6570;&#x5185;&#x90E8;&#xFF0C;&#x53EA;&#x8981;&#x662F;&#x5728;&#x5168;&#x5C40;&#x73AF;&#x5883;&#x4E0B;&#x8FD0;&#x884C;&#xFF0C;<code>this</code>&#x5C31;&#x662F;&#x6307;&#x9876;&#x5C42;&#x5BF9;&#x8C61;<code>window</code>&#x3002;</p>
<p><strong>&#xFF08;2&#xFF09;&#x6784;&#x9020;&#x51FD;&#x6570;</strong></p>
<p>&#x6784;&#x9020;&#x51FD;&#x6570;&#x4E2D;&#x7684;<code>this</code>&#xFF0C;&#x6307;&#x7684;&#x662F;&#x5B9E;&#x4F8B;&#x5BF9;&#x8C61;&#x3002;</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> Obj = <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">p</span>) </span>{
  <span class="hljs-keyword">this</span>.p = p;
};
</code></pre>
<p>&#x4E0A;&#x9762;&#x4EE3;&#x7801;&#x5B9A;&#x4E49;&#x4E86;&#x4E00;&#x4E2A;&#x6784;&#x9020;&#x51FD;&#x6570;<code>Obj</code>&#x3002;&#x7531;&#x4E8E;<code>this</code>&#x6307;&#x5411;&#x5B9E;&#x4F8B;&#x5BF9;&#x8C61;&#xFF0C;&#x6240;&#x4EE5;&#x5728;&#x6784;&#x9020;&#x51FD;&#x6570;&#x5185;&#x90E8;&#x5B9A;&#x4E49;<code>this.p</code>&#xFF0C;&#x5C31;&#x76F8;&#x5F53;&#x4E8E;&#x5B9A;&#x4E49;&#x5B9E;&#x4F8B;&#x5BF9;&#x8C61;&#x6709;&#x4E00;&#x4E2A;<code>p</code>&#x5C5E;&#x6027;&#x3002;</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> o = <span class="hljs-keyword">new</span> Obj(<span class="hljs-string">&apos;Hello World!&apos;</span>);
o.p <span class="hljs-comment">// &quot;Hello World!&quot;</span>
</code></pre>
<p><strong>&#xFF08;3&#xFF09;&#x5BF9;&#x8C61;&#x7684;&#x65B9;&#x6CD5;</strong></p>
<p>&#x5982;&#x679C;&#x5BF9;&#x8C61;&#x7684;&#x65B9;&#x6CD5;&#x91CC;&#x9762;&#x5305;&#x542B;<code>this</code>&#xFF0C;<code>this</code>&#x7684;&#x6307;&#x5411;&#x5C31;&#x662F;&#x65B9;&#x6CD5;&#x8FD0;&#x884C;&#x65F6;&#x6240;&#x5728;&#x7684;&#x5BF9;&#x8C61;&#x3002;&#x8BE5;&#x65B9;&#x6CD5;&#x8D4B;&#x503C;&#x7ED9;&#x53E6;&#x4E00;&#x4E2A;&#x5BF9;&#x8C61;&#xFF0C;&#x5C31;&#x4F1A;&#x6539;&#x53D8;<code>this</code>&#x7684;&#x6307;&#x5411;&#x3002;</p>
<p>&#x4F46;&#x662F;&#xFF0C;&#x8FD9;&#x6761;&#x89C4;&#x5219;&#x5F88;&#x4E0D;&#x5BB9;&#x6613;&#x628A;&#x63E1;&#x3002;&#x8BF7;&#x770B;&#x4E0B;&#x9762;&#x7684;&#x4EE3;&#x7801;&#x3002;</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> obj ={
  foo: <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) </span>{
    <span class="hljs-built_in">console</span>.log(<span class="hljs-keyword">this</span>);
  }
};

obj.foo() <span class="hljs-comment">// obj</span>
</code></pre>
<p>&#x4E0A;&#x9762;&#x4EE3;&#x7801;&#x4E2D;&#xFF0C;<code>obj.foo</code>&#x65B9;&#x6CD5;&#x6267;&#x884C;&#x65F6;&#xFF0C;&#x5B83;&#x5185;&#x90E8;&#x7684;<code>this</code>&#x6307;&#x5411;<code>obj</code>&#x3002;</p>
<p>&#x4F46;&#x662F;&#xFF0C;&#x4E0B;&#x9762;&#x8FD9;&#x51E0;&#x79CD;&#x7528;&#x6CD5;&#xFF0C;&#x90FD;&#x4F1A;&#x6539;&#x53D8;<code>this</code>&#x7684;&#x6307;&#x5411;&#x3002;</p>
<pre><code class="lang-javascript"><span class="hljs-comment">// &#x60C5;&#x51B5;&#x4E00;</span>
(obj.foo = obj.foo)() <span class="hljs-comment">// window</span>
<span class="hljs-comment">// &#x60C5;&#x51B5;&#x4E8C;</span>
(<span class="hljs-literal">false</span> || obj.foo)() <span class="hljs-comment">// window</span>
<span class="hljs-comment">// &#x60C5;&#x51B5;&#x4E09;</span>
(<span class="hljs-number">1</span>, obj.foo)() <span class="hljs-comment">// window</span>
</code></pre>
<p>&#x4E0A;&#x9762;&#x4EE3;&#x7801;&#x4E2D;&#xFF0C;<code>obj.foo</code>&#x5C31;&#x662F;&#x4E00;&#x4E2A;&#x503C;&#x3002;&#x8FD9;&#x4E2A;&#x503C;&#x771F;&#x6B63;&#x8C03;&#x7528;&#x7684;&#x65F6;&#x5019;&#xFF0C;&#x8FD0;&#x884C;&#x73AF;&#x5883;&#x5DF2;&#x7ECF;&#x4E0D;&#x662F;<code>obj</code>&#x4E86;&#xFF0C;&#x800C;&#x662F;&#x5168;&#x5C40;&#x73AF;&#x5883;&#xFF0C;&#x6240;&#x4EE5;<code>this</code>&#x4E0D;&#x518D;&#x6307;&#x5411;<code>obj</code>&#x3002;</p>
<p>&#x53EF;&#x4EE5;&#x8FD9;&#x6837;&#x7406;&#x89E3;&#xFF0C;JavaScript &#x5F15;&#x64CE;&#x5185;&#x90E8;&#xFF0C;<code>obj</code>&#x548C;<code>obj.foo</code>&#x50A8;&#x5B58;&#x5728;&#x4E24;&#x4E2A;&#x5185;&#x5B58;&#x5730;&#x5740;&#xFF0C;&#x79F0;&#x4E3A;&#x5730;&#x5740;&#x4E00;&#x548C;&#x5730;&#x5740;&#x4E8C;&#x3002;<code>obj.foo()</code>&#x8FD9;&#x6837;&#x8C03;&#x7528;&#x65F6;&#xFF0C;&#x662F;&#x4ECE;&#x5730;&#x5740;&#x4E00;&#x8C03;&#x7528;&#x5730;&#x5740;&#x4E8C;&#xFF0C;&#x56E0;&#x6B64;&#x5730;&#x5740;&#x4E8C;&#x7684;&#x8FD0;&#x884C;&#x73AF;&#x5883;&#x662F;&#x5730;&#x5740;&#x4E00;&#xFF0C;<code>this</code>&#x6307;&#x5411;<code>obj</code>&#x3002;&#x4F46;&#x662F;&#xFF0C;&#x4E0A;&#x9762;&#x4E09;&#x79CD;&#x60C5;&#x51B5;&#xFF0C;&#x90FD;&#x662F;&#x76F4;&#x63A5;&#x53D6;&#x51FA;&#x5730;&#x5740;&#x4E8C;&#x8FDB;&#x884C;&#x8C03;&#x7528;&#xFF0C;&#x8FD9;&#x6837;&#x7684;&#x8BDD;&#xFF0C;&#x8FD0;&#x884C;&#x73AF;&#x5883;&#x5C31;&#x662F;&#x5168;&#x5C40;&#x73AF;&#x5883;&#xFF0C;&#x56E0;&#x6B64;<code>this</code>&#x6307;&#x5411;&#x5168;&#x5C40;&#x73AF;&#x5883;&#x3002;&#x4E0A;&#x9762;&#x4E09;&#x79CD;&#x60C5;&#x51B5;&#x7B49;&#x540C;&#x4E8E;&#x4E0B;&#x9762;&#x7684;&#x4EE3;&#x7801;&#x3002;</p>
<pre><code class="lang-javascript"><span class="hljs-comment">// &#x60C5;&#x51B5;&#x4E00;</span>
(obj.foo = <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) </span>{
  <span class="hljs-built_in">console</span>.log(<span class="hljs-keyword">this</span>);
})()
<span class="hljs-comment">// &#x7B49;&#x540C;&#x4E8E;</span>
(<span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) </span>{
  <span class="hljs-built_in">console</span>.log(<span class="hljs-keyword">this</span>);
})()

<span class="hljs-comment">// &#x60C5;&#x51B5;&#x4E8C;</span>
(<span class="hljs-literal">false</span> || <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) </span>{
  <span class="hljs-built_in">console</span>.log(<span class="hljs-keyword">this</span>);
})()

<span class="hljs-comment">// &#x60C5;&#x51B5;&#x4E09;</span>
(<span class="hljs-number">1</span>, <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) </span>{
  <span class="hljs-built_in">console</span>.log(<span class="hljs-keyword">this</span>);
})()
</code></pre>
<p>&#x5982;&#x679C;<code>this</code>&#x6240;&#x5728;&#x7684;&#x65B9;&#x6CD5;&#x4E0D;&#x5728;&#x5BF9;&#x8C61;&#x7684;&#x7B2C;&#x4E00;&#x5C42;&#xFF0C;&#x8FD9;&#x65F6;<code>this</code>&#x53EA;&#x662F;&#x6307;&#x5411;&#x5F53;&#x524D;&#x4E00;&#x5C42;&#x7684;&#x5BF9;&#x8C61;&#xFF0C;&#x800C;&#x4E0D;&#x4F1A;&#x7EE7;&#x627F;&#x66F4;&#x4E0A;&#x9762;&#x7684;&#x5C42;&#x3002;</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> a = {
  p: <span class="hljs-string">&apos;Hello&apos;</span>,
  b: {
    m: <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params"></span>) </span>{
      <span class="hljs-built_in">console</span>.log(<span class="hljs-keyword">this</span>.p);
    }
  }
};

a.b.m() <span class="hljs-comment">// undefined</span>
</code></pre>
<p>&#x4E0A;&#x9762;&#x4EE3;&#x7801;&#x4E2D;&#xFF0C;<code>a.b.m</code>&#x65B9;&#x6CD5;&#x5728;<code>a</code>&#x5BF9;&#x8C61;&#x7684;&#x7B2C;&#x4E8C;&#x5C42;&#xFF0C;&#x8BE5;&#x65B9;&#x6CD5;&#x5185;&#x90E8;&#x7684;<code>this</code>&#x4E0D;&#x662F;&#x6307;&#x5411;<code>a</code>&#xFF0C;&#x800C;&#x662F;&#x6307;&#x5411;<code>a.b</code>&#xFF0C;&#x56E0;&#x4E3A;&#x5B9E;&#x9645;&#x6267;&#x884C;&#x7684;&#x662F;&#x4E0B;&#x9762;&#x7684;&#x4EE3;&#x7801;&#x3002;</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> b = {
  m: <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params"></span>) </span>{
   <span class="hljs-built_in">console</span>.log(<span class="hljs-keyword">this</span>.p);
  }
};

<span class="hljs-keyword">var</span> a = {
  p: <span class="hljs-string">&apos;Hello&apos;</span>,
  b: b
};

(a.b).m() <span class="hljs-comment">// &#x7B49;&#x540C;&#x4E8E; b.m()</span>
</code></pre>
<p>&#x5982;&#x679C;&#x8981;&#x8FBE;&#x5230;&#x9884;&#x671F;&#x6548;&#x679C;&#xFF0C;&#x53EA;&#x6709;&#x5199;&#x6210;&#x4E0B;&#x9762;&#x8FD9;&#x6837;&#x3002;</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> a = {
  b: {
    m: <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params"></span>) </span>{
      <span class="hljs-built_in">console</span>.log(<span class="hljs-keyword">this</span>.p);
    },
    p: <span class="hljs-string">&apos;Hello&apos;</span>
  }
};
</code></pre>
<p>&#x5982;&#x679C;&#x8FD9;&#x65F6;&#x5C06;&#x5D4C;&#x5957;&#x5BF9;&#x8C61;&#x5185;&#x90E8;&#x7684;&#x65B9;&#x6CD5;&#x8D4B;&#x503C;&#x7ED9;&#x4E00;&#x4E2A;&#x53D8;&#x91CF;&#xFF0C;<code>this</code>&#x4F9D;&#x7136;&#x4F1A;&#x6307;&#x5411;&#x5168;&#x5C40;&#x5BF9;&#x8C61;&#x3002;</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> a = {
  b: {
    m: <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params"></span>) </span>{
      <span class="hljs-built_in">console</span>.log(<span class="hljs-keyword">this</span>.p);
    },
    p: <span class="hljs-string">&apos;Hello&apos;</span>
  }
};

<span class="hljs-keyword">var</span> hello = a.b.m;
hello() <span class="hljs-comment">// undefined</span>
</code></pre>
<p>&#x4E0A;&#x9762;&#x4EE3;&#x7801;&#x4E2D;&#xFF0C;<code>m</code>&#x662F;&#x591A;&#x5C42;&#x5BF9;&#x8C61;&#x5185;&#x90E8;&#x7684;&#x4E00;&#x4E2A;&#x65B9;&#x6CD5;&#x3002;&#x4E3A;&#x6C42;&#x7B80;&#x4FBF;&#xFF0C;&#x5C06;&#x5176;&#x8D4B;&#x503C;&#x7ED9;<code>hello</code>&#x53D8;&#x91CF;&#xFF0C;&#x7ED3;&#x679C;&#x8C03;&#x7528;&#x65F6;&#xFF0C;<code>this</code>&#x6307;&#x5411;&#x4E86;&#x9876;&#x5C42;&#x5BF9;&#x8C61;&#x3002;&#x4E3A;&#x4E86;&#x907F;&#x514D;&#x8FD9;&#x4E2A;&#x95EE;&#x9898;&#xFF0C;&#x53EF;&#x4EE5;&#x53EA;&#x5C06;<code>m</code>&#x6240;&#x5728;&#x7684;&#x5BF9;&#x8C61;&#x8D4B;&#x503C;&#x7ED9;<code>hello</code>&#xFF0C;&#x8FD9;&#x6837;&#x8C03;&#x7528;&#x65F6;&#xFF0C;<code>this</code>&#x7684;&#x6307;&#x5411;&#x5C31;&#x4E0D;&#x4F1A;&#x53D8;&#x3002;</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> hello = a.b;
hello.m() <span class="hljs-comment">// Hello</span>
</code></pre>
<h2 id="&#x4F7F;&#x7528;&#x6CE8;&#x610F;&#x70B9;">&#x4F7F;&#x7528;&#x6CE8;&#x610F;&#x70B9;</h2>
<h3 id="&#x907F;&#x514D;&#x591A;&#x5C42;-this">&#x907F;&#x514D;&#x591A;&#x5C42; this</h3>
<p>&#x7531;&#x4E8E;<code>this</code>&#x7684;&#x6307;&#x5411;&#x662F;&#x4E0D;&#x786E;&#x5B9A;&#x7684;&#xFF0C;&#x6240;&#x4EE5;&#x5207;&#x52FF;&#x5728;&#x51FD;&#x6570;&#x4E2D;&#x5305;&#x542B;&#x591A;&#x5C42;&#x7684;<code>this</code>&#x3002;</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> o = {
  f1: <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) </span>{
    <span class="hljs-built_in">console</span>.log(<span class="hljs-keyword">this</span>);
    <span class="hljs-keyword">var</span> f2 = <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) </span>{
      <span class="hljs-built_in">console</span>.log(<span class="hljs-keyword">this</span>);
    }();
  }
}

o.f1()
<span class="hljs-comment">// Object</span>
<span class="hljs-comment">// Window</span>
</code></pre>
<p>&#x4E0A;&#x9762;&#x4EE3;&#x7801;&#x5305;&#x542B;&#x4E24;&#x5C42;<code>this</code>&#xFF0C;&#x7ED3;&#x679C;&#x8FD0;&#x884C;&#x540E;&#xFF0C;&#x7B2C;&#x4E00;&#x5C42;&#x6307;&#x5411;&#x5BF9;&#x8C61;<code>o</code>&#xFF0C;&#x7B2C;&#x4E8C;&#x5C42;&#x6307;&#x5411;&#x5168;&#x5C40;&#x5BF9;&#x8C61;&#xFF0C;&#x56E0;&#x4E3A;&#x5B9E;&#x9645;&#x6267;&#x884C;&#x7684;&#x662F;&#x4E0B;&#x9762;&#x7684;&#x4EE3;&#x7801;&#x3002;</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> temp = <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) </span>{
  <span class="hljs-built_in">console</span>.log(<span class="hljs-keyword">this</span>);
};

<span class="hljs-keyword">var</span> o = {
  f1: <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) </span>{
    <span class="hljs-built_in">console</span>.log(<span class="hljs-keyword">this</span>);
    <span class="hljs-keyword">var</span> f2 = temp();
  }
}
</code></pre>
<p>&#x4E00;&#x4E2A;&#x89E3;&#x51B3;&#x65B9;&#x6CD5;&#x662F;&#x5728;&#x7B2C;&#x4E8C;&#x5C42;&#x6539;&#x7528;&#x4E00;&#x4E2A;&#x6307;&#x5411;&#x5916;&#x5C42;<code>this</code>&#x7684;&#x53D8;&#x91CF;&#x3002;</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> o = {
  f1: <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params"></span>) </span>{
    <span class="hljs-built_in">console</span>.log(<span class="hljs-keyword">this</span>);
    <span class="hljs-keyword">var</span> that = <span class="hljs-keyword">this</span>;
    <span class="hljs-keyword">var</span> f2 = <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params"></span>) </span>{
      <span class="hljs-built_in">console</span>.log(that);
    }();
  }
}

o.f1()
<span class="hljs-comment">// Object</span>
<span class="hljs-comment">// Object</span>
</code></pre>
<p>&#x4E0A;&#x9762;&#x4EE3;&#x7801;&#x5B9A;&#x4E49;&#x4E86;&#x53D8;&#x91CF;<code>that</code>&#xFF0C;&#x56FA;&#x5B9A;&#x6307;&#x5411;&#x5916;&#x5C42;&#x7684;<code>this</code>&#xFF0C;&#x7136;&#x540E;&#x5728;&#x5185;&#x5C42;&#x4F7F;&#x7528;<code>that</code>&#xFF0C;&#x5C31;&#x4E0D;&#x4F1A;&#x53D1;&#x751F;<code>this</code>&#x6307;&#x5411;&#x7684;&#x6539;&#x53D8;&#x3002;</p>
<p>&#x4E8B;&#x5B9E;&#x4E0A;&#xFF0C;&#x4F7F;&#x7528;&#x4E00;&#x4E2A;&#x53D8;&#x91CF;&#x56FA;&#x5B9A;<code>this</code>&#x7684;&#x503C;&#xFF0C;&#x7136;&#x540E;&#x5185;&#x5C42;&#x51FD;&#x6570;&#x8C03;&#x7528;&#x8FD9;&#x4E2A;&#x53D8;&#x91CF;&#xFF0C;&#x662F;&#x975E;&#x5E38;&#x5E38;&#x89C1;&#x7684;&#x505A;&#x6CD5;&#xFF0C;&#x8BF7;&#x52A1;&#x5FC5;&#x638C;&#x63E1;&#x3002;</p>
<p>JavaScript &#x63D0;&#x4F9B;&#x4E86;&#x4E25;&#x683C;&#x6A21;&#x5F0F;&#xFF0C;&#x4E5F;&#x53EF;&#x4EE5;&#x786C;&#x6027;&#x907F;&#x514D;&#x8FD9;&#x79CD;&#x95EE;&#x9898;&#x3002;&#x4E25;&#x683C;&#x6A21;&#x5F0F;&#x4E0B;&#xFF0C;&#x5982;&#x679C;&#x51FD;&#x6570;&#x5185;&#x90E8;&#x7684;<code>this</code>&#x6307;&#x5411;&#x9876;&#x5C42;&#x5BF9;&#x8C61;&#xFF0C;&#x5C31;&#x4F1A;&#x62A5;&#x9519;&#x3002;</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> counter = {
  count: <span class="hljs-number">0</span>
};
counter.inc = <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) </span>{
<span class="hljs-meta">  &apos;use strict&apos;</span>;
  <span class="hljs-keyword">this</span>.count++
};
<span class="hljs-keyword">var</span> f = counter.inc;
f()
<span class="hljs-comment">// TypeError: Cannot read property &apos;count&apos; of undefined</span>
</code></pre>
<p>&#x4E0A;&#x9762;&#x4EE3;&#x7801;&#x4E2D;&#xFF0C;<code>inc</code>&#x65B9;&#x6CD5;&#x901A;&#x8FC7;<code>&apos;use strict&apos;</code>&#x58F0;&#x660E;&#x91C7;&#x7528;&#x4E25;&#x683C;&#x6A21;&#x5F0F;&#xFF0C;&#x8FD9;&#x65F6;&#x5185;&#x90E8;&#x7684;<code>this</code>&#x4E00;&#x65E6;&#x6307;&#x5411;&#x9876;&#x5C42;&#x5BF9;&#x8C61;&#xFF0C;&#x5C31;&#x4F1A;&#x62A5;&#x9519;&#x3002;</p>
<h3 id="&#x907F;&#x514D;&#x6570;&#x7EC4;&#x5904;&#x7406;&#x65B9;&#x6CD5;&#x4E2D;&#x7684;-this">&#x907F;&#x514D;&#x6570;&#x7EC4;&#x5904;&#x7406;&#x65B9;&#x6CD5;&#x4E2D;&#x7684; this</h3>
<p>&#x6570;&#x7EC4;&#x7684;<code>map</code>&#x548C;<code>foreach</code>&#x65B9;&#x6CD5;&#xFF0C;&#x5141;&#x8BB8;&#x63D0;&#x4F9B;&#x4E00;&#x4E2A;&#x51FD;&#x6570;&#x4F5C;&#x4E3A;&#x53C2;&#x6570;&#x3002;&#x8FD9;&#x4E2A;&#x51FD;&#x6570;&#x5185;&#x90E8;&#x4E0D;&#x5E94;&#x8BE5;&#x4F7F;&#x7528;<code>this</code>&#x3002;</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> o = {
  v: <span class="hljs-string">&apos;hello&apos;</span>,
  p: [ <span class="hljs-string">&apos;a1&apos;</span>, <span class="hljs-string">&apos;a2&apos;</span> ],
  f: <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">f</span>(<span class="hljs-params"></span>) </span>{
    <span class="hljs-keyword">this</span>.p.forEach(<span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">item</span>) </span>{
      <span class="hljs-built_in">console</span>.log(<span class="hljs-keyword">this</span>.v + <span class="hljs-string">&apos; &apos;</span> + item);
    });
  }
}

o.f()
<span class="hljs-comment">// undefined a1</span>
<span class="hljs-comment">// undefined a2</span>
</code></pre>
<p>&#x4E0A;&#x9762;&#x4EE3;&#x7801;&#x4E2D;&#xFF0C;<code>foreach</code>&#x65B9;&#x6CD5;&#x7684;&#x56DE;&#x8C03;&#x51FD;&#x6570;&#x4E2D;&#x7684;<code>this</code>&#xFF0C;&#x5176;&#x5B9E;&#x662F;&#x6307;&#x5411;<code>window</code>&#x5BF9;&#x8C61;&#xFF0C;&#x56E0;&#x6B64;&#x53D6;&#x4E0D;&#x5230;<code>o.v</code>&#x7684;&#x503C;&#x3002;&#x539F;&#x56E0;&#x8DDF;&#x4E0A;&#x4E00;&#x6BB5;&#x7684;&#x591A;&#x5C42;<code>this</code>&#x662F;&#x4E00;&#x6837;&#x7684;&#xFF0C;&#x5C31;&#x662F;&#x5185;&#x5C42;&#x7684;<code>this</code>&#x4E0D;&#x6307;&#x5411;&#x5916;&#x90E8;&#xFF0C;&#x800C;&#x6307;&#x5411;&#x9876;&#x5C42;&#x5BF9;&#x8C61;&#x3002;</p>
<p>&#x89E3;&#x51B3;&#x8FD9;&#x4E2A;&#x95EE;&#x9898;&#x7684;&#x4E00;&#x79CD;&#x65B9;&#x6CD5;&#xFF0C;&#x5C31;&#x662F;&#x524D;&#x9762;&#x63D0;&#x5230;&#x7684;&#xFF0C;&#x4F7F;&#x7528;&#x4E2D;&#x95F4;&#x53D8;&#x91CF;&#x56FA;&#x5B9A;<code>this</code>&#x3002;</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> o = {
  v: <span class="hljs-string">&apos;hello&apos;</span>,
  p: [ <span class="hljs-string">&apos;a1&apos;</span>, <span class="hljs-string">&apos;a2&apos;</span> ],
  f: <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">f</span>(<span class="hljs-params"></span>) </span>{
    <span class="hljs-keyword">var</span> that = <span class="hljs-keyword">this</span>;
    <span class="hljs-keyword">this</span>.p.forEach(<span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">item</span>) </span>{
      <span class="hljs-built_in">console</span>.log(that.v+<span class="hljs-string">&apos; &apos;</span>+item);
    });
  }
}

o.f()
<span class="hljs-comment">// hello a1</span>
<span class="hljs-comment">// hello a2</span>
</code></pre>
<p>&#x53E6;&#x4E00;&#x79CD;&#x65B9;&#x6CD5;&#x662F;&#x5C06;<code>this</code>&#x5F53;&#x4F5C;<code>foreach</code>&#x65B9;&#x6CD5;&#x7684;&#x7B2C;&#x4E8C;&#x4E2A;&#x53C2;&#x6570;&#xFF0C;&#x56FA;&#x5B9A;&#x5B83;&#x7684;&#x8FD0;&#x884C;&#x73AF;&#x5883;&#x3002;</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> o = {
  v: <span class="hljs-string">&apos;hello&apos;</span>,
  p: [ <span class="hljs-string">&apos;a1&apos;</span>, <span class="hljs-string">&apos;a2&apos;</span> ],
  f: <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">f</span>(<span class="hljs-params"></span>) </span>{
    <span class="hljs-keyword">this</span>.p.forEach(<span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">item</span>) </span>{
      <span class="hljs-built_in">console</span>.log(<span class="hljs-keyword">this</span>.v + <span class="hljs-string">&apos; &apos;</span> + item);
    }, <span class="hljs-keyword">this</span>);
  }
}

o.f()
<span class="hljs-comment">// hello a1</span>
<span class="hljs-comment">// hello a2</span>
</code></pre>
<h3 id="&#x907F;&#x514D;&#x56DE;&#x8C03;&#x51FD;&#x6570;&#x4E2D;&#x7684;-this">&#x907F;&#x514D;&#x56DE;&#x8C03;&#x51FD;&#x6570;&#x4E2D;&#x7684; this</h3>
<p>&#x56DE;&#x8C03;&#x51FD;&#x6570;&#x4E2D;&#x7684;<code>this</code>&#x5F80;&#x5F80;&#x4F1A;&#x6539;&#x53D8;&#x6307;&#x5411;&#xFF0C;&#x6700;&#x597D;&#x907F;&#x514D;&#x4F7F;&#x7528;&#x3002;</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> o = <span class="hljs-keyword">new</span> <span class="hljs-built_in">Object</span>();
o.f = <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) </span>{
  <span class="hljs-built_in">console</span>.log(<span class="hljs-keyword">this</span> === o);
}

<span class="hljs-comment">// jQuery &#x7684;&#x5199;&#x6CD5;</span>
$(<span class="hljs-string">&apos;#button&apos;</span>).on(<span class="hljs-string">&apos;click&apos;</span>, o.f);
</code></pre>
<p>&#x4E0A;&#x9762;&#x4EE3;&#x7801;&#x4E2D;&#xFF0C;&#x70B9;&#x51FB;&#x6309;&#x94AE;&#x4EE5;&#x540E;&#xFF0C;&#x63A7;&#x5236;&#x53F0;&#x4F1A;&#x663E;&#x793A;<code>false</code>&#x3002;&#x539F;&#x56E0;&#x662F;&#x6B64;&#x65F6;<code>this</code>&#x4E0D;&#x518D;&#x6307;&#x5411;<code>o</code>&#x5BF9;&#x8C61;&#xFF0C;&#x800C;&#x662F;&#x6307;&#x5411;&#x6309;&#x94AE;&#x7684; DOM &#x5BF9;&#x8C61;&#xFF0C;&#x56E0;&#x4E3A;<code>f</code>&#x65B9;&#x6CD5;&#x662F;&#x5728;&#x6309;&#x94AE;&#x5BF9;&#x8C61;&#x7684;&#x73AF;&#x5883;&#x4E2D;&#x88AB;&#x8C03;&#x7528;&#x7684;&#x3002;&#x8FD9;&#x79CD;&#x7EC6;&#x5FAE;&#x7684;&#x5DEE;&#x522B;&#xFF0C;&#x5F88;&#x5BB9;&#x6613;&#x5728;&#x7F16;&#x7A0B;&#x4E2D;&#x5FFD;&#x89C6;&#xFF0C;&#x5BFC;&#x81F4;&#x96BE;&#x4EE5;&#x5BDF;&#x89C9;&#x7684;&#x9519;&#x8BEF;&#x3002;</p>
<p>&#x4E3A;&#x4E86;&#x89E3;&#x51B3;&#x8FD9;&#x4E2A;&#x95EE;&#x9898;&#xFF0C;&#x53EF;&#x4EE5;&#x91C7;&#x7528;&#x4E0B;&#x9762;&#x7684;&#x4E00;&#x4E9B;&#x65B9;&#x6CD5;&#x5BF9;<code>this</code>&#x8FDB;&#x884C;&#x7ED1;&#x5B9A;&#xFF0C;&#x4E5F;&#x5C31;&#x662F;&#x4F7F;&#x5F97;<code>this</code>&#x56FA;&#x5B9A;&#x6307;&#x5411;&#x67D0;&#x4E2A;&#x5BF9;&#x8C61;&#xFF0C;&#x51CF;&#x5C11;&#x4E0D;&#x786E;&#x5B9A;&#x6027;&#x3002;</p>
<h2 id="&#x7ED1;&#x5B9A;-this-&#x7684;&#x65B9;&#x6CD5;">&#x7ED1;&#x5B9A; this &#x7684;&#x65B9;&#x6CD5;</h2>
<p><code>this</code>&#x7684;&#x52A8;&#x6001;&#x5207;&#x6362;&#xFF0C;&#x56FA;&#x7136;&#x4E3A; JavaScript &#x521B;&#x9020;&#x4E86;&#x5DE8;&#x5927;&#x7684;&#x7075;&#x6D3B;&#x6027;&#xFF0C;&#x4F46;&#x4E5F;&#x4F7F;&#x5F97;&#x7F16;&#x7A0B;&#x53D8;&#x5F97;&#x56F0;&#x96BE;&#x548C;&#x6A21;&#x7CCA;&#x3002;&#x6709;&#x65F6;&#xFF0C;&#x9700;&#x8981;&#x628A;<code>this</code>&#x56FA;&#x5B9A;&#x4E0B;&#x6765;&#xFF0C;&#x907F;&#x514D;&#x51FA;&#x73B0;&#x610F;&#x60F3;&#x4E0D;&#x5230;&#x7684;&#x60C5;&#x51B5;&#x3002;JavaScript &#x63D0;&#x4F9B;&#x4E86;<code>call</code>&#x3001;<code>apply</code>&#x3001;<code>bind</code>&#x8FD9;&#x4E09;&#x4E2A;&#x65B9;&#x6CD5;&#xFF0C;&#x6765;&#x5207;&#x6362;/&#x56FA;&#x5B9A;<code>this</code>&#x7684;&#x6307;&#x5411;&#x3002;</p>
<h3 id="functionprototypecall">Function.prototype.call()</h3>
<p>&#x51FD;&#x6570;&#x5B9E;&#x4F8B;&#x7684;<code>call</code>&#x65B9;&#x6CD5;&#xFF0C;&#x53EF;&#x4EE5;&#x6307;&#x5B9A;&#x51FD;&#x6570;&#x5185;&#x90E8;<code>this</code>&#x7684;&#x6307;&#x5411;&#xFF08;&#x5373;&#x51FD;&#x6570;&#x6267;&#x884C;&#x65F6;&#x6240;&#x5728;&#x7684;&#x4F5C;&#x7528;&#x57DF;&#xFF09;&#xFF0C;&#x7136;&#x540E;&#x5728;&#x6240;&#x6307;&#x5B9A;&#x7684;&#x4F5C;&#x7528;&#x57DF;&#x4E2D;&#xFF0C;&#x8C03;&#x7528;&#x8BE5;&#x51FD;&#x6570;&#x3002;</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> obj = {};

<span class="hljs-keyword">var</span> f = <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) </span>{
  <span class="hljs-keyword">return</span> <span class="hljs-keyword">this</span>;
};

f() === <span class="hljs-built_in">window</span> <span class="hljs-comment">// true</span>
f.call(obj) === obj <span class="hljs-comment">// true</span>
</code></pre>
<p>&#x4E0A;&#x9762;&#x4EE3;&#x7801;&#x4E2D;&#xFF0C;&#x5168;&#x5C40;&#x73AF;&#x5883;&#x8FD0;&#x884C;&#x51FD;&#x6570;<code>f</code>&#x65F6;&#xFF0C;<code>this</code>&#x6307;&#x5411;&#x5168;&#x5C40;&#x73AF;&#x5883;&#xFF08;&#x6D4F;&#x89C8;&#x5668;&#x4E3A;<code>window</code>&#x5BF9;&#x8C61;&#xFF09;&#xFF1B;<code>call</code>&#x65B9;&#x6CD5;&#x53EF;&#x4EE5;&#x6539;&#x53D8;<code>this</code>&#x7684;&#x6307;&#x5411;&#xFF0C;&#x6307;&#x5B9A;<code>this</code>&#x6307;&#x5411;&#x5BF9;&#x8C61;<code>obj</code>&#xFF0C;&#x7136;&#x540E;&#x5728;&#x5BF9;&#x8C61;<code>obj</code>&#x7684;&#x4F5C;&#x7528;&#x57DF;&#x4E2D;&#x8FD0;&#x884C;&#x51FD;&#x6570;<code>f</code>&#x3002;</p>
<p><code>call</code>&#x65B9;&#x6CD5;&#x7684;&#x53C2;&#x6570;&#xFF0C;&#x5E94;&#x8BE5;&#x662F;&#x4E00;&#x4E2A;&#x5BF9;&#x8C61;&#x3002;&#x5982;&#x679C;&#x53C2;&#x6570;&#x4E3A;&#x7A7A;&#x3001;<code>null</code>&#x548C;<code>undefined</code>&#xFF0C;&#x5219;&#x9ED8;&#x8BA4;&#x4F20;&#x5165;&#x5168;&#x5C40;&#x5BF9;&#x8C61;&#x3002;</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> n = <span class="hljs-number">123</span>;
<span class="hljs-keyword">var</span> obj = { n: <span class="hljs-number">456</span> };

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">a</span>(<span class="hljs-params"></span>) </span>{
  <span class="hljs-built_in">console</span>.log(<span class="hljs-keyword">this</span>.n);
}

a.call() <span class="hljs-comment">// 123</span>
a.call(<span class="hljs-literal">null</span>) <span class="hljs-comment">// 123</span>
a.call(<span class="hljs-literal">undefined</span>) <span class="hljs-comment">// 123</span>
a.call(<span class="hljs-built_in">window</span>) <span class="hljs-comment">// 123</span>
a.call(obj) <span class="hljs-comment">// 456</span>
</code></pre>
<p>&#x4E0A;&#x9762;&#x4EE3;&#x7801;&#x4E2D;&#xFF0C;<code>a</code>&#x51FD;&#x6570;&#x4E2D;&#x7684;<code>this</code>&#x5173;&#x952E;&#x5B57;&#xFF0C;&#x5982;&#x679C;&#x6307;&#x5411;&#x5168;&#x5C40;&#x5BF9;&#x8C61;&#xFF0C;&#x8FD4;&#x56DE;&#x7ED3;&#x679C;&#x4E3A;<code>123</code>&#x3002;&#x5982;&#x679C;&#x4F7F;&#x7528;<code>call</code>&#x65B9;&#x6CD5;&#x5C06;<code>this</code>&#x5173;&#x952E;&#x5B57;&#x6307;&#x5411;<code>obj</code>&#x5BF9;&#x8C61;&#xFF0C;&#x8FD4;&#x56DE;&#x7ED3;&#x679C;&#x4E3A;<code>456</code>&#x3002;&#x53EF;&#x4EE5;&#x770B;&#x5230;&#xFF0C;&#x5982;&#x679C;<code>call</code>&#x65B9;&#x6CD5;&#x6CA1;&#x6709;&#x53C2;&#x6570;&#xFF0C;&#x6216;&#x8005;&#x53C2;&#x6570;&#x4E3A;<code>null</code>&#x6216;<code>undefined</code>&#xFF0C;&#x5219;&#x7B49;&#x540C;&#x4E8E;&#x6307;&#x5411;&#x5168;&#x5C40;&#x5BF9;&#x8C61;&#x3002;</p>
<p>&#x5982;&#x679C;<code>call</code>&#x65B9;&#x6CD5;&#x7684;&#x53C2;&#x6570;&#x662F;&#x4E00;&#x4E2A;&#x539F;&#x59CB;&#x503C;&#xFF0C;&#x90A3;&#x4E48;&#x8FD9;&#x4E2A;&#x539F;&#x59CB;&#x503C;&#x4F1A;&#x81EA;&#x52A8;&#x8F6C;&#x6210;&#x5BF9;&#x5E94;&#x7684;&#x5305;&#x88C5;&#x5BF9;&#x8C61;&#xFF0C;&#x7136;&#x540E;&#x4F20;&#x5165;<code>call</code>&#x65B9;&#x6CD5;&#x3002;</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> f = <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) </span>{
  <span class="hljs-keyword">return</span> <span class="hljs-keyword">this</span>;
};

f.call(<span class="hljs-number">5</span>)
<span class="hljs-comment">// Number {[[PrimitiveValue]]: 5}</span>
</code></pre>
<p>&#x4E0A;&#x9762;&#x4EE3;&#x7801;&#x4E2D;&#xFF0C;<code>call</code>&#x7684;&#x53C2;&#x6570;&#x4E3A;<code>5</code>&#xFF0C;&#x4E0D;&#x662F;&#x5BF9;&#x8C61;&#xFF0C;&#x4F1A;&#x88AB;&#x81EA;&#x52A8;&#x8F6C;&#x6210;&#x5305;&#x88C5;&#x5BF9;&#x8C61;&#xFF08;<code>Number</code>&#x7684;&#x5B9E;&#x4F8B;&#xFF09;&#xFF0C;&#x7ED1;&#x5B9A;<code>f</code>&#x5185;&#x90E8;&#x7684;<code>this</code>&#x3002;</p>
<p><code>call</code>&#x65B9;&#x6CD5;&#x8FD8;&#x53EF;&#x4EE5;&#x63A5;&#x53D7;&#x591A;&#x4E2A;&#x53C2;&#x6570;&#x3002;</p>
<pre><code class="lang-javascript">func.call(thisValue, arg1, arg2, ...)
</code></pre>
<p><code>call</code>&#x7684;&#x7B2C;&#x4E00;&#x4E2A;&#x53C2;&#x6570;&#x5C31;&#x662F;<code>this</code>&#x6240;&#x8981;&#x6307;&#x5411;&#x7684;&#x90A3;&#x4E2A;&#x5BF9;&#x8C61;&#xFF0C;&#x540E;&#x9762;&#x7684;&#x53C2;&#x6570;&#x5219;&#x662F;&#x51FD;&#x6570;&#x8C03;&#x7528;&#x65F6;&#x6240;&#x9700;&#x7684;&#x53C2;&#x6570;&#x3002;</p>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">add</span>(<span class="hljs-params">a, b</span>) </span>{
  <span class="hljs-keyword">return</span> a + b;
}

add.call(<span class="hljs-keyword">this</span>, <span class="hljs-number">1</span>, <span class="hljs-number">2</span>) <span class="hljs-comment">// 3</span>
</code></pre>
<p>&#x4E0A;&#x9762;&#x4EE3;&#x7801;&#x4E2D;&#xFF0C;<code>call</code>&#x65B9;&#x6CD5;&#x6307;&#x5B9A;&#x51FD;&#x6570;<code>add</code>&#x5185;&#x90E8;&#x7684;<code>this</code>&#x7ED1;&#x5B9A;&#x5F53;&#x524D;&#x73AF;&#x5883;&#xFF08;&#x5BF9;&#x8C61;&#xFF09;&#xFF0C;&#x5E76;&#x4E14;&#x53C2;&#x6570;&#x4E3A;<code>1</code>&#x548C;<code>2</code>&#xFF0C;&#x56E0;&#x6B64;&#x51FD;&#x6570;<code>add</code>&#x8FD0;&#x884C;&#x540E;&#x5F97;&#x5230;<code>3</code>&#x3002;</p>
<p><code>call</code>&#x65B9;&#x6CD5;&#x7684;&#x4E00;&#x4E2A;&#x5E94;&#x7528;&#x662F;&#x8C03;&#x7528;&#x5BF9;&#x8C61;&#x7684;&#x539F;&#x751F;&#x65B9;&#x6CD5;&#x3002;</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> obj = {};
obj.hasOwnProperty(<span class="hljs-string">&apos;toString&apos;</span>) <span class="hljs-comment">// false</span>

<span class="hljs-comment">// &#x8986;&#x76D6;&#x6389;&#x7EE7;&#x627F;&#x7684; hasOwnProperty &#x65B9;&#x6CD5;</span>
obj.hasOwnProperty = <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) </span>{
  <span class="hljs-keyword">return</span> <span class="hljs-literal">true</span>;
};
obj.hasOwnProperty(<span class="hljs-string">&apos;toString&apos;</span>) <span class="hljs-comment">// true</span>

<span class="hljs-built_in">Object</span>.prototype.hasOwnProperty.call(obj, <span class="hljs-string">&apos;toString&apos;</span>) <span class="hljs-comment">// false</span>
</code></pre>
<p>&#x4E0A;&#x9762;&#x4EE3;&#x7801;&#x4E2D;&#xFF0C;<code>hasOwnProperty</code>&#x662F;<code>obj</code>&#x5BF9;&#x8C61;&#x7EE7;&#x627F;&#x7684;&#x65B9;&#x6CD5;&#xFF0C;&#x5982;&#x679C;&#x8FD9;&#x4E2A;&#x65B9;&#x6CD5;&#x4E00;&#x65E6;&#x88AB;&#x8986;&#x76D6;&#xFF0C;&#x5C31;&#x4E0D;&#x4F1A;&#x5F97;&#x5230;&#x6B63;&#x786E;&#x7ED3;&#x679C;&#x3002;<code>call</code>&#x65B9;&#x6CD5;&#x53EF;&#x4EE5;&#x89E3;&#x51B3;&#x8FD9;&#x4E2A;&#x95EE;&#x9898;&#xFF0C;&#x5B83;&#x5C06;<code>hasOwnProperty</code>&#x65B9;&#x6CD5;&#x7684;&#x539F;&#x59CB;&#x5B9A;&#x4E49;&#x653E;&#x5230;<code>obj</code>&#x5BF9;&#x8C61;&#x4E0A;&#x6267;&#x884C;&#xFF0C;&#x8FD9;&#x6837;&#x65E0;&#x8BBA;<code>obj</code>&#x4E0A;&#x6709;&#x6CA1;&#x6709;&#x540C;&#x540D;&#x65B9;&#x6CD5;&#xFF0C;&#x90FD;&#x4E0D;&#x4F1A;&#x5F71;&#x54CD;&#x7ED3;&#x679C;&#x3002;</p>
<h3 id="functionprototypeapply">Function.prototype.apply()</h3>
<p><code>apply</code>&#x65B9;&#x6CD5;&#x7684;&#x4F5C;&#x7528;&#x4E0E;<code>call</code>&#x65B9;&#x6CD5;&#x7C7B;&#x4F3C;&#xFF0C;&#x4E5F;&#x662F;&#x6539;&#x53D8;<code>this</code>&#x6307;&#x5411;&#xFF0C;&#x7136;&#x540E;&#x518D;&#x8C03;&#x7528;&#x8BE5;&#x51FD;&#x6570;&#x3002;&#x552F;&#x4E00;&#x7684;&#x533A;&#x522B;&#x5C31;&#x662F;&#xFF0C;&#x5B83;&#x63A5;&#x6536;&#x4E00;&#x4E2A;&#x6570;&#x7EC4;&#x4F5C;&#x4E3A;&#x51FD;&#x6570;&#x6267;&#x884C;&#x65F6;&#x7684;&#x53C2;&#x6570;&#xFF0C;&#x4F7F;&#x7528;&#x683C;&#x5F0F;&#x5982;&#x4E0B;&#x3002;</p>
<pre><code class="lang-javascript">func.apply(thisValue, [arg1, arg2, ...])
</code></pre>
<p><code>apply</code>&#x65B9;&#x6CD5;&#x7684;&#x7B2C;&#x4E00;&#x4E2A;&#x53C2;&#x6570;&#x4E5F;&#x662F;<code>this</code>&#x6240;&#x8981;&#x6307;&#x5411;&#x7684;&#x90A3;&#x4E2A;&#x5BF9;&#x8C61;&#xFF0C;&#x5982;&#x679C;&#x8BBE;&#x4E3A;<code>null</code>&#x6216;<code>undefined</code>&#xFF0C;&#x5219;&#x7B49;&#x540C;&#x4E8E;&#x6307;&#x5B9A;&#x5168;&#x5C40;&#x5BF9;&#x8C61;&#x3002;&#x7B2C;&#x4E8C;&#x4E2A;&#x53C2;&#x6570;&#x5219;&#x662F;&#x4E00;&#x4E2A;&#x6570;&#x7EC4;&#xFF0C;&#x8BE5;&#x6570;&#x7EC4;&#x7684;&#x6240;&#x6709;&#x6210;&#x5458;&#x4F9D;&#x6B21;&#x4F5C;&#x4E3A;&#x53C2;&#x6570;&#xFF0C;&#x4F20;&#x5165;&#x539F;&#x51FD;&#x6570;&#x3002;&#x539F;&#x51FD;&#x6570;&#x7684;&#x53C2;&#x6570;&#xFF0C;&#x5728;<code>call</code>&#x65B9;&#x6CD5;&#x4E2D;&#x5FC5;&#x987B;&#x4E00;&#x4E2A;&#x4E2A;&#x6DFB;&#x52A0;&#xFF0C;&#x4F46;&#x662F;&#x5728;<code>apply</code>&#x65B9;&#x6CD5;&#x4E2D;&#xFF0C;&#x5FC5;&#x987B;&#x4EE5;&#x6570;&#x7EC4;&#x5F62;&#x5F0F;&#x6DFB;&#x52A0;&#x3002;</p>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">f</span>(<span class="hljs-params">x, y</span>)</span>{
  <span class="hljs-built_in">console</span>.log(x + y);
}

f.call(<span class="hljs-literal">null</span>, <span class="hljs-number">1</span>, <span class="hljs-number">1</span>) <span class="hljs-comment">// 2</span>
f.apply(<span class="hljs-literal">null</span>, [<span class="hljs-number">1</span>, <span class="hljs-number">1</span>]) <span class="hljs-comment">// 2</span>
</code></pre>
<p>&#x4E0A;&#x9762;&#x4EE3;&#x7801;&#x4E2D;&#xFF0C;<code>f</code>&#x51FD;&#x6570;&#x672C;&#x6765;&#x63A5;&#x53D7;&#x4E24;&#x4E2A;&#x53C2;&#x6570;&#xFF0C;&#x4F7F;&#x7528;<code>apply</code>&#x65B9;&#x6CD5;&#x4EE5;&#x540E;&#xFF0C;&#x5C31;&#x53D8;&#x6210;&#x53EF;&#x4EE5;&#x63A5;&#x53D7;&#x4E00;&#x4E2A;&#x6570;&#x7EC4;&#x4F5C;&#x4E3A;&#x53C2;&#x6570;&#x3002;</p>
<p>&#x5229;&#x7528;&#x8FD9;&#x4E00;&#x70B9;&#xFF0C;&#x53EF;&#x4EE5;&#x505A;&#x4E00;&#x4E9B;&#x6709;&#x8DA3;&#x7684;&#x5E94;&#x7528;&#x3002;</p>
<p><strong>&#xFF08;1&#xFF09;&#x627E;&#x51FA;&#x6570;&#x7EC4;&#x6700;&#x5927;&#x5143;&#x7D20;</strong></p>
<p>JavaScript &#x4E0D;&#x63D0;&#x4F9B;&#x627E;&#x51FA;&#x6570;&#x7EC4;&#x6700;&#x5927;&#x5143;&#x7D20;&#x7684;&#x51FD;&#x6570;&#x3002;&#x7ED3;&#x5408;&#x4F7F;&#x7528;<code>apply</code>&#x65B9;&#x6CD5;&#x548C;<code>Math.max</code>&#x65B9;&#x6CD5;&#xFF0C;&#x5C31;&#x53EF;&#x4EE5;&#x8FD4;&#x56DE;&#x6570;&#x7EC4;&#x7684;&#x6700;&#x5927;&#x5143;&#x7D20;&#x3002;</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> a = [<span class="hljs-number">10</span>, <span class="hljs-number">2</span>, <span class="hljs-number">4</span>, <span class="hljs-number">15</span>, <span class="hljs-number">9</span>];
<span class="hljs-built_in">Math</span>.max.apply(<span class="hljs-literal">null</span>, a) <span class="hljs-comment">// 15</span>
</code></pre>
<p><strong>&#xFF08;2&#xFF09;&#x5C06;&#x6570;&#x7EC4;&#x7684;&#x7A7A;&#x5143;&#x7D20;&#x53D8;&#x4E3A;<code>undefined</code></strong></p>
<p>&#x901A;&#x8FC7;<code>apply</code>&#x65B9;&#x6CD5;&#xFF0C;&#x5229;&#x7528;<code>Array</code>&#x6784;&#x9020;&#x51FD;&#x6570;&#x5C06;&#x6570;&#x7EC4;&#x7684;&#x7A7A;&#x5143;&#x7D20;&#x53D8;&#x6210;<code>undefined</code>&#x3002;</p>
<pre><code class="lang-javascript"><span class="hljs-built_in">Array</span>.apply(<span class="hljs-literal">null</span>, [<span class="hljs-string">&apos;a&apos;</span>, ,<span class="hljs-string">&apos;b&apos;</span>])
<span class="hljs-comment">// [ &apos;a&apos;, undefined, &apos;b&apos; ]</span>
</code></pre>
<p>&#x7A7A;&#x5143;&#x7D20;&#x4E0E;<code>undefined</code>&#x7684;&#x5DEE;&#x522B;&#x5728;&#x4E8E;&#xFF0C;&#x6570;&#x7EC4;&#x7684;<code>forEach</code>&#x65B9;&#x6CD5;&#x4F1A;&#x8DF3;&#x8FC7;&#x7A7A;&#x5143;&#x7D20;&#xFF0C;&#x4F46;&#x662F;&#x4E0D;&#x4F1A;&#x8DF3;&#x8FC7;<code>undefined</code>&#x3002;&#x56E0;&#x6B64;&#xFF0C;&#x904D;&#x5386;&#x5185;&#x90E8;&#x5143;&#x7D20;&#x7684;&#x65F6;&#x5019;&#xFF0C;&#x4F1A;&#x5F97;&#x5230;&#x4E0D;&#x540C;&#x7684;&#x7ED3;&#x679C;&#x3002;</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> a = [<span class="hljs-string">&apos;a&apos;</span>, , <span class="hljs-string">&apos;b&apos;</span>];

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">print</span>(<span class="hljs-params">i</span>) </span>{
  <span class="hljs-built_in">console</span>.log(i);
}

a.forEach(print)
<span class="hljs-comment">// a</span>
<span class="hljs-comment">// b</span>

<span class="hljs-built_in">Array</span>.apply(<span class="hljs-literal">null</span>, a).forEach(print)
<span class="hljs-comment">// a</span>
<span class="hljs-comment">// undefined</span>
<span class="hljs-comment">// b</span>
</code></pre>
<p><strong>&#xFF08;3&#xFF09;&#x8F6C;&#x6362;&#x7C7B;&#x4F3C;&#x6570;&#x7EC4;&#x7684;&#x5BF9;&#x8C61;</strong></p>
<p>&#x53E6;&#x5916;&#xFF0C;&#x5229;&#x7528;&#x6570;&#x7EC4;&#x5BF9;&#x8C61;&#x7684;<code>slice</code>&#x65B9;&#x6CD5;&#xFF0C;&#x53EF;&#x4EE5;&#x5C06;&#x4E00;&#x4E2A;&#x7C7B;&#x4F3C;&#x6570;&#x7EC4;&#x7684;&#x5BF9;&#x8C61;&#xFF08;&#x6BD4;&#x5982;<code>arguments</code>&#x5BF9;&#x8C61;&#xFF09;&#x8F6C;&#x4E3A;&#x771F;&#x6B63;&#x7684;&#x6570;&#x7EC4;&#x3002;</p>
<pre><code class="lang-javascript"><span class="hljs-built_in">Array</span>.prototype.slice.apply({<span class="hljs-number">0</span>: <span class="hljs-number">1</span>, length: <span class="hljs-number">1</span>}) <span class="hljs-comment">// [1]</span>
<span class="hljs-built_in">Array</span>.prototype.slice.apply({<span class="hljs-number">0</span>: <span class="hljs-number">1</span>}) <span class="hljs-comment">// []</span>
<span class="hljs-built_in">Array</span>.prototype.slice.apply({<span class="hljs-number">0</span>: <span class="hljs-number">1</span>, length: <span class="hljs-number">2</span>}) <span class="hljs-comment">// [1, undefined]</span>
<span class="hljs-built_in">Array</span>.prototype.slice.apply({length: <span class="hljs-number">1</span>}) <span class="hljs-comment">// [undefined]</span>
</code></pre>
<p>&#x4E0A;&#x9762;&#x4EE3;&#x7801;&#x7684;<code>apply</code>&#x65B9;&#x6CD5;&#x7684;&#x53C2;&#x6570;&#x90FD;&#x662F;&#x5BF9;&#x8C61;&#xFF0C;&#x4F46;&#x662F;&#x8FD4;&#x56DE;&#x7ED3;&#x679C;&#x90FD;&#x662F;&#x6570;&#x7EC4;&#xFF0C;&#x8FD9;&#x5C31;&#x8D77;&#x5230;&#x4E86;&#x5C06;&#x5BF9;&#x8C61;&#x8F6C;&#x6210;&#x6570;&#x7EC4;&#x7684;&#x76EE;&#x7684;&#x3002;&#x4ECE;&#x4E0A;&#x9762;&#x4EE3;&#x7801;&#x53EF;&#x4EE5;&#x770B;&#x5230;&#xFF0C;&#x8FD9;&#x4E2A;&#x65B9;&#x6CD5;&#x8D77;&#x4F5C;&#x7528;&#x7684;&#x524D;&#x63D0;&#x662F;&#xFF0C;&#x88AB;&#x5904;&#x7406;&#x7684;&#x5BF9;&#x8C61;&#x5FC5;&#x987B;&#x6709;<code>length</code>&#x5C5E;&#x6027;&#xFF0C;&#x4EE5;&#x53CA;&#x76F8;&#x5BF9;&#x5E94;&#x7684;&#x6570;&#x5B57;&#x952E;&#x3002;</p>
<p><strong>&#xFF08;4&#xFF09;&#x7ED1;&#x5B9A;&#x56DE;&#x8C03;&#x51FD;&#x6570;&#x7684;&#x5BF9;&#x8C61;</strong></p>
<p>&#x524D;&#x9762;&#x7684;&#x6309;&#x94AE;&#x70B9;&#x51FB;&#x4E8B;&#x4EF6;&#x7684;&#x4F8B;&#x5B50;&#xFF0C;&#x53EF;&#x4EE5;&#x6539;&#x5199;&#x5982;&#x4E0B;&#x3002;</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> o = <span class="hljs-keyword">new</span> <span class="hljs-built_in">Object</span>();

o.f = <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) </span>{
  <span class="hljs-built_in">console</span>.log(<span class="hljs-keyword">this</span> === o);
}

<span class="hljs-keyword">var</span> f = <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params"></span>)</span>{
  o.f.apply(o);
  <span class="hljs-comment">// &#x6216;&#x8005; o.f.call(o);</span>
};

<span class="hljs-comment">// jQuery &#x7684;&#x5199;&#x6CD5;</span>
$(<span class="hljs-string">&apos;#button&apos;</span>).on(<span class="hljs-string">&apos;click&apos;</span>, f);
</code></pre>
<p>&#x4E0A;&#x9762;&#x4EE3;&#x7801;&#x4E2D;&#xFF0C;&#x70B9;&#x51FB;&#x6309;&#x94AE;&#x4EE5;&#x540E;&#xFF0C;&#x63A7;&#x5236;&#x53F0;&#x5C06;&#x4F1A;&#x663E;&#x793A;<code>true</code>&#x3002;&#x7531;&#x4E8E;<code>apply</code>&#x65B9;&#x6CD5;&#xFF08;&#x6216;&#x8005;<code>call</code>&#x65B9;&#x6CD5;&#xFF09;&#x4E0D;&#x4EC5;&#x7ED1;&#x5B9A;&#x51FD;&#x6570;&#x6267;&#x884C;&#x65F6;&#x6240;&#x5728;&#x7684;&#x5BF9;&#x8C61;&#xFF0C;&#x8FD8;&#x4F1A;&#x7ACB;&#x5373;&#x6267;&#x884C;&#x51FD;&#x6570;&#xFF0C;&#x56E0;&#x6B64;&#x4E0D;&#x5F97;&#x4E0D;&#x628A;&#x7ED1;&#x5B9A;&#x8BED;&#x53E5;&#x5199;&#x5728;&#x4E00;&#x4E2A;&#x51FD;&#x6570;&#x4F53;&#x5185;&#x3002;&#x66F4;&#x7B80;&#x6D01;&#x7684;&#x5199;&#x6CD5;&#x662F;&#x91C7;&#x7528;&#x4E0B;&#x9762;&#x4ECB;&#x7ECD;&#x7684;<code>bind</code>&#x65B9;&#x6CD5;&#x3002;</p>
<h3 id="functionprototypebind">Function.prototype.bind()</h3>
<p><code>bind</code>&#x65B9;&#x6CD5;&#x7528;&#x4E8E;&#x5C06;&#x51FD;&#x6570;&#x4F53;&#x5185;&#x7684;<code>this</code>&#x7ED1;&#x5B9A;&#x5230;&#x67D0;&#x4E2A;&#x5BF9;&#x8C61;&#xFF0C;&#x7136;&#x540E;&#x8FD4;&#x56DE;&#x4E00;&#x4E2A;&#x65B0;&#x51FD;&#x6570;&#x3002;</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> d = <span class="hljs-keyword">new</span> <span class="hljs-built_in">Date</span>();
d.getTime() <span class="hljs-comment">// 1481869925657</span>

<span class="hljs-keyword">var</span> print = d.getTime;
print() <span class="hljs-comment">// Uncaught TypeError: this is not a Date object.</span>
</code></pre>
<p>&#x4E0A;&#x9762;&#x4EE3;&#x7801;&#x4E2D;&#xFF0C;&#x6211;&#x4EEC;&#x5C06;<code>d.getTime</code>&#x65B9;&#x6CD5;&#x8D4B;&#x7ED9;&#x53D8;&#x91CF;<code>print</code>&#xFF0C;&#x7136;&#x540E;&#x8C03;&#x7528;<code>print</code>&#x5C31;&#x62A5;&#x9519;&#x4E86;&#x3002;&#x8FD9;&#x662F;&#x56E0;&#x4E3A;<code>getTime</code>&#x65B9;&#x6CD5;&#x5185;&#x90E8;&#x7684;<code>this</code>&#xFF0C;&#x7ED1;&#x5B9A;<code>Date</code>&#x5BF9;&#x8C61;&#x7684;&#x5B9E;&#x4F8B;&#xFF0C;&#x8D4B;&#x7ED9;&#x53D8;&#x91CF;<code>print</code>&#x4EE5;&#x540E;&#xFF0C;&#x5185;&#x90E8;&#x7684;<code>this</code>&#x5DF2;&#x7ECF;&#x4E0D;&#x6307;&#x5411;<code>Date</code>&#x5BF9;&#x8C61;&#x7684;&#x5B9E;&#x4F8B;&#x4E86;&#x3002;</p>
<p><code>bind</code>&#x65B9;&#x6CD5;&#x53EF;&#x4EE5;&#x89E3;&#x51B3;&#x8FD9;&#x4E2A;&#x95EE;&#x9898;&#x3002;</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> print = d.getTime.bind(d);
print() <span class="hljs-comment">// 1481869925657</span>
</code></pre>
<p>&#x4E0A;&#x9762;&#x4EE3;&#x7801;&#x4E2D;&#xFF0C;<code>bind</code>&#x65B9;&#x6CD5;&#x5C06;<code>getTime</code>&#x65B9;&#x6CD5;&#x5185;&#x90E8;&#x7684;<code>this</code>&#x7ED1;&#x5B9A;&#x5230;<code>d</code>&#x5BF9;&#x8C61;&#xFF0C;&#x8FD9;&#x65F6;&#x5C31;&#x53EF;&#x4EE5;&#x5B89;&#x5168;&#x5730;&#x5C06;&#x8FD9;&#x4E2A;&#x65B9;&#x6CD5;&#x8D4B;&#x503C;&#x7ED9;&#x5176;&#x4ED6;&#x53D8;&#x91CF;&#x4E86;&#x3002;</p>
<p><code>bind</code>&#x65B9;&#x6CD5;&#x7684;&#x53C2;&#x6570;&#x5C31;&#x662F;&#x6240;&#x8981;&#x7ED1;&#x5B9A;<code>this</code>&#x7684;&#x5BF9;&#x8C61;&#xFF0C;&#x4E0B;&#x9762;&#x662F;&#x4E00;&#x4E2A;&#x66F4;&#x6E05;&#x6670;&#x7684;&#x4F8B;&#x5B50;&#x3002;</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> counter = {
  count: <span class="hljs-number">0</span>,
  inc: <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) </span>{
    <span class="hljs-keyword">this</span>.count++;
  }
};

<span class="hljs-keyword">var</span> func = counter.inc.bind(counter);
func();
counter.count <span class="hljs-comment">// 1</span>
</code></pre>
<p>&#x4E0A;&#x9762;&#x4EE3;&#x7801;&#x4E2D;&#xFF0C;<code>counter.inc</code>&#x65B9;&#x6CD5;&#x88AB;&#x8D4B;&#x503C;&#x7ED9;&#x53D8;&#x91CF;<code>func</code>&#x3002;&#x8FD9;&#x65F6;&#x5FC5;&#x987B;&#x7528;<code>bind</code>&#x65B9;&#x6CD5;&#x5C06;<code>inc</code>&#x5185;&#x90E8;&#x7684;<code>this</code>&#xFF0C;&#x7ED1;&#x5B9A;&#x5230;<code>counter</code>&#xFF0C;&#x5426;&#x5219;&#x5C31;&#x4F1A;&#x51FA;&#x9519;&#x3002;</p>
<p><code>this</code>&#x7ED1;&#x5B9A;&#x5230;&#x5176;&#x4ED6;&#x5BF9;&#x8C61;&#x4E5F;&#x662F;&#x53EF;&#x4EE5;&#x7684;&#x3002;</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> counter = {
  count: <span class="hljs-number">0</span>,
  inc: <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) </span>{
    <span class="hljs-keyword">this</span>.count++;
  }
};

<span class="hljs-keyword">var</span> obj = {
  count: <span class="hljs-number">100</span>
};
<span class="hljs-keyword">var</span> func = counter.inc.bind(obj);
func();
obj.count <span class="hljs-comment">// 101</span>
</code></pre>
<p>&#x4E0A;&#x9762;&#x4EE3;&#x7801;&#x4E2D;&#xFF0C;<code>bind</code>&#x65B9;&#x6CD5;&#x5C06;<code>inc</code>&#x65B9;&#x6CD5;&#x5185;&#x90E8;&#x7684;<code>this</code>&#xFF0C;&#x7ED1;&#x5B9A;&#x5230;<code>obj</code>&#x5BF9;&#x8C61;&#x3002;&#x7ED3;&#x679C;&#x8C03;&#x7528;<code>func</code>&#x51FD;&#x6570;&#x4EE5;&#x540E;&#xFF0C;&#x9012;&#x589E;&#x7684;&#x5C31;&#x662F;<code>obj</code>&#x5185;&#x90E8;&#x7684;<code>count</code>&#x5C5E;&#x6027;&#x3002;</p>
<p><code>bind</code>&#x8FD8;&#x53EF;&#x4EE5;&#x63A5;&#x53D7;&#x66F4;&#x591A;&#x7684;&#x53C2;&#x6570;&#xFF0C;&#x5C06;&#x8FD9;&#x4E9B;&#x53C2;&#x6570;&#x7ED1;&#x5B9A;&#x539F;&#x51FD;&#x6570;&#x7684;&#x53C2;&#x6570;&#x3002;</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> add = <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">x, y</span>) </span>{
  <span class="hljs-keyword">return</span> x * <span class="hljs-keyword">this</span>.m + y * <span class="hljs-keyword">this</span>.n;
}

<span class="hljs-keyword">var</span> obj = {
  m: <span class="hljs-number">2</span>,
  n: <span class="hljs-number">2</span>
};

<span class="hljs-keyword">var</span> newAdd = add.bind(obj, <span class="hljs-number">5</span>);
newAdd(<span class="hljs-number">5</span>) <span class="hljs-comment">// 20</span>
</code></pre>
<p>&#x4E0A;&#x9762;&#x4EE3;&#x7801;&#x4E2D;&#xFF0C;<code>bind</code>&#x65B9;&#x6CD5;&#x9664;&#x4E86;&#x7ED1;&#x5B9A;<code>this</code>&#x5BF9;&#x8C61;&#xFF0C;&#x8FD8;&#x5C06;<code>add</code>&#x51FD;&#x6570;&#x7684;&#x7B2C;&#x4E00;&#x4E2A;&#x53C2;&#x6570;<code>x</code>&#x7ED1;&#x5B9A;&#x6210;<code>5</code>&#xFF0C;&#x7136;&#x540E;&#x8FD4;&#x56DE;&#x4E00;&#x4E2A;&#x65B0;&#x51FD;&#x6570;<code>newAdd</code>&#xFF0C;&#x8FD9;&#x4E2A;&#x51FD;&#x6570;&#x53EA;&#x8981;&#x518D;&#x63A5;&#x53D7;&#x4E00;&#x4E2A;&#x53C2;&#x6570;<code>y</code>&#x5C31;&#x80FD;&#x8FD0;&#x884C;&#x4E86;&#x3002;</p>
<p>&#x5982;&#x679C;<code>bind</code>&#x65B9;&#x6CD5;&#x7684;&#x7B2C;&#x4E00;&#x4E2A;&#x53C2;&#x6570;&#x662F;<code>null</code>&#x6216;<code>undefined</code>&#xFF0C;&#x7B49;&#x4E8E;&#x5C06;<code>this</code>&#x7ED1;&#x5B9A;&#x5230;&#x5168;&#x5C40;&#x5BF9;&#x8C61;&#xFF0C;&#x51FD;&#x6570;&#x8FD0;&#x884C;&#x65F6;<code>this</code>&#x6307;&#x5411;&#x9876;&#x5C42;&#x5BF9;&#x8C61;&#xFF08;&#x6D4F;&#x89C8;&#x5668;&#x4E3A;<code>window</code>&#xFF09;&#x3002;</p>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">add</span>(<span class="hljs-params">x, y</span>) </span>{
  <span class="hljs-keyword">return</span> x + y;
}

<span class="hljs-keyword">var</span> plus5 = add.bind(<span class="hljs-literal">null</span>, <span class="hljs-number">5</span>);
plus5(<span class="hljs-number">10</span>) <span class="hljs-comment">// 15</span>
</code></pre>
<p>&#x4E0A;&#x9762;&#x4EE3;&#x7801;&#x4E2D;&#xFF0C;&#x51FD;&#x6570;<code>add</code>&#x5185;&#x90E8;&#x5E76;&#x6CA1;&#x6709;<code>this</code>&#xFF0C;&#x4F7F;&#x7528;<code>bind</code>&#x65B9;&#x6CD5;&#x7684;&#x4E3B;&#x8981;&#x76EE;&#x7684;&#x662F;&#x7ED1;&#x5B9A;&#x53C2;&#x6570;<code>x</code>&#xFF0C;&#x4EE5;&#x540E;&#x6BCF;&#x6B21;&#x8FD0;&#x884C;&#x65B0;&#x51FD;&#x6570;<code>plus5</code>&#xFF0C;&#x5C31;&#x53EA;&#x9700;&#x8981;&#x63D0;&#x4F9B;&#x53E6;&#x4E00;&#x4E2A;&#x53C2;&#x6570;<code>y</code>&#x5C31;&#x591F;&#x4E86;&#x3002;&#x800C;&#x4E14;&#x56E0;&#x4E3A;<code>add</code>&#x5185;&#x90E8;&#x6CA1;&#x6709;<code>this</code>&#xFF0C;&#x6240;&#x4EE5;<code>bind</code>&#x7684;&#x7B2C;&#x4E00;&#x4E2A;&#x53C2;&#x6570;&#x662F;<code>null</code>&#xFF0C;&#x4E0D;&#x8FC7;&#x8FD9;&#x91CC;&#x5982;&#x679C;&#x662F;&#x5176;&#x4ED6;&#x5BF9;&#x8C61;&#xFF0C;&#x4E5F;&#x6CA1;&#x6709;&#x5F71;&#x54CD;&#x3002;</p>
<p><code>bind</code>&#x65B9;&#x6CD5;&#x6709;&#x4E00;&#x4E9B;&#x4F7F;&#x7528;&#x6CE8;&#x610F;&#x70B9;&#x3002;</p>
<p><strong>&#xFF08;1&#xFF09;&#x6BCF;&#x4E00;&#x6B21;&#x8FD4;&#x56DE;&#x4E00;&#x4E2A;&#x65B0;&#x51FD;&#x6570;</strong></p>
<p><code>bind</code>&#x65B9;&#x6CD5;&#x6BCF;&#x8FD0;&#x884C;&#x4E00;&#x6B21;&#xFF0C;&#x5C31;&#x8FD4;&#x56DE;&#x4E00;&#x4E2A;&#x65B0;&#x51FD;&#x6570;&#xFF0C;&#x8FD9;&#x4F1A;&#x4EA7;&#x751F;&#x4E00;&#x4E9B;&#x95EE;&#x9898;&#x3002;&#x6BD4;&#x5982;&#xFF0C;&#x76D1;&#x542C;&#x4E8B;&#x4EF6;&#x7684;&#x65F6;&#x5019;&#xFF0C;&#x4E0D;&#x80FD;&#x5199;&#x6210;&#x4E0B;&#x9762;&#x8FD9;&#x6837;&#x3002;</p>
<pre><code class="lang-javascript">element.addEventListener(<span class="hljs-string">&apos;click&apos;</span>, o.m.bind(o));
</code></pre>
<p>&#x4E0A;&#x9762;&#x4EE3;&#x7801;&#x4E2D;&#xFF0C;<code>click</code>&#x4E8B;&#x4EF6;&#x7ED1;&#x5B9A;<code>bind</code>&#x65B9;&#x6CD5;&#x751F;&#x6210;&#x7684;&#x4E00;&#x4E2A;&#x533F;&#x540D;&#x51FD;&#x6570;&#x3002;&#x8FD9;&#x6837;&#x4F1A;&#x5BFC;&#x81F4;&#x65E0;&#x6CD5;&#x53D6;&#x6D88;&#x7ED1;&#x5B9A;&#xFF0C;&#x6240;&#x4EE5;&#xFF0C;&#x4E0B;&#x9762;&#x7684;&#x4EE3;&#x7801;&#x662F;&#x65E0;&#x6548;&#x7684;&#x3002;</p>
<pre><code class="lang-javascript">element.removeEventListener(<span class="hljs-string">&apos;click&apos;</span>, o.m.bind(o));
</code></pre>
<p>&#x6B63;&#x786E;&#x7684;&#x65B9;&#x6CD5;&#x662F;&#x5199;&#x6210;&#x4E0B;&#x9762;&#x8FD9;&#x6837;&#xFF1A;</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> listener = o.m.bind(o);
element.addEventListener(<span class="hljs-string">&apos;click&apos;</span>, listener);
<span class="hljs-comment">//  ...</span>
element.removeEventListener(<span class="hljs-string">&apos;click&apos;</span>, listener);
</code></pre>
<p><strong>&#xFF08;2&#xFF09;&#x7ED3;&#x5408;&#x56DE;&#x8C03;&#x51FD;&#x6570;&#x4F7F;&#x7528;</strong></p>
<p>&#x56DE;&#x8C03;&#x51FD;&#x6570;&#x662F; JavaScript &#x6700;&#x5E38;&#x7528;&#x7684;&#x6A21;&#x5F0F;&#x4E4B;&#x4E00;&#xFF0C;&#x4F46;&#x662F;&#x4E00;&#x4E2A;&#x5E38;&#x89C1;&#x7684;&#x9519;&#x8BEF;&#x662F;&#xFF0C;&#x5C06;&#x5305;&#x542B;<code>this</code>&#x7684;&#x65B9;&#x6CD5;&#x76F4;&#x63A5;&#x5F53;&#x4F5C;&#x56DE;&#x8C03;&#x51FD;&#x6570;&#x3002;&#x89E3;&#x51B3;&#x65B9;&#x6CD5;&#x5C31;&#x662F;&#x4F7F;&#x7528;<code>bind</code>&#x65B9;&#x6CD5;&#xFF0C;&#x5C06;<code>counter.inc</code>&#x7ED1;&#x5B9A;<code>counter</code>&#x3002;</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> counter = {
  count: <span class="hljs-number">0</span>,
  inc: <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) </span>{
<span class="hljs-meta">    &apos;use strict&apos;</span>;
    <span class="hljs-keyword">this</span>.count++;
  }
};

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">callIt</span>(<span class="hljs-params">callback</span>) </span>{
  callback();
}

callIt(counter.inc.bind(counter));
counter.count <span class="hljs-comment">// 1</span>
</code></pre>
<p>&#x4E0A;&#x9762;&#x4EE3;&#x7801;&#x4E2D;&#xFF0C;<code>callIt</code>&#x65B9;&#x6CD5;&#x4F1A;&#x8C03;&#x7528;&#x56DE;&#x8C03;&#x51FD;&#x6570;&#x3002;&#x8FD9;&#x65F6;&#x5982;&#x679C;&#x76F4;&#x63A5;&#x628A;<code>counter.inc</code>&#x4F20;&#x5165;&#xFF0C;&#x8C03;&#x7528;&#x65F6;<code>counter.inc</code>&#x5185;&#x90E8;&#x7684;<code>this</code>&#x5C31;&#x4F1A;&#x6307;&#x5411;&#x5168;&#x5C40;&#x5BF9;&#x8C61;&#x3002;&#x4F7F;&#x7528;<code>bind</code>&#x65B9;&#x6CD5;&#x5C06;<code>counter.inc</code>&#x7ED1;&#x5B9A;<code>counter</code>&#x4EE5;&#x540E;&#xFF0C;&#x5C31;&#x4E0D;&#x4F1A;&#x6709;&#x8FD9;&#x4E2A;&#x95EE;&#x9898;&#xFF0C;<code>this</code>&#x603B;&#x662F;&#x6307;&#x5411;<code>counter</code>&#x3002;</p>
<p>&#x8FD8;&#x6709;&#x4E00;&#x79CD;&#x60C5;&#x51B5;&#x6BD4;&#x8F83;&#x9690;&#x853D;&#xFF0C;&#x5C31;&#x662F;&#x67D0;&#x4E9B;&#x6570;&#x7EC4;&#x65B9;&#x6CD5;&#x53EF;&#x4EE5;&#x63A5;&#x53D7;&#x4E00;&#x4E2A;&#x51FD;&#x6570;&#x5F53;&#x4F5C;&#x53C2;&#x6570;&#x3002;&#x8FD9;&#x4E9B;&#x51FD;&#x6570;&#x5185;&#x90E8;&#x7684;<code>this</code>&#x6307;&#x5411;&#xFF0C;&#x5F88;&#x53EF;&#x80FD;&#x4E5F;&#x4F1A;&#x51FA;&#x9519;&#x3002;</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> obj = {
  name: <span class="hljs-string">&apos;&#x5F20;&#x4E09;&apos;</span>,
  times: [<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>],
  print: <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) </span>{
    <span class="hljs-keyword">this</span>.times.forEach(<span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">n</span>) </span>{
      <span class="hljs-built_in">console</span>.log(<span class="hljs-keyword">this</span>.name);
    });
  }
};

obj.print()
<span class="hljs-comment">// &#x6CA1;&#x6709;&#x4EFB;&#x4F55;&#x8F93;&#x51FA;</span>
</code></pre>
<p>&#x4E0A;&#x9762;&#x4EE3;&#x7801;&#x4E2D;&#xFF0C;<code>obj.print</code>&#x5185;&#x90E8;<code>this.times</code>&#x7684;<code>this</code>&#x662F;&#x6307;&#x5411;<code>obj</code>&#x7684;&#xFF0C;&#x8FD9;&#x4E2A;&#x6CA1;&#x6709;&#x95EE;&#x9898;&#x3002;&#x4F46;&#x662F;&#xFF0C;<code>forEach</code>&#x65B9;&#x6CD5;&#x7684;&#x56DE;&#x8C03;&#x51FD;&#x6570;&#x5185;&#x90E8;&#x7684;<code>this.name</code>&#x5374;&#x662F;&#x6307;&#x5411;&#x5168;&#x5C40;&#x5BF9;&#x8C61;&#xFF0C;&#x5BFC;&#x81F4;&#x6CA1;&#x6709;&#x529E;&#x6CD5;&#x53D6;&#x5230;&#x503C;&#x3002;&#x7A0D;&#x5FAE;&#x6539;&#x52A8;&#x4E00;&#x4E0B;&#xFF0C;&#x5C31;&#x53EF;&#x4EE5;&#x770B;&#x5F97;&#x66F4;&#x6E05;&#x695A;&#x3002;</p>
<pre><code class="lang-javascript">obj.print = <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) </span>{
  <span class="hljs-keyword">this</span>.times.forEach(<span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">n</span>) </span>{
    <span class="hljs-built_in">console</span>.log(<span class="hljs-keyword">this</span> === <span class="hljs-built_in">window</span>);
  });
};

obj.print()
<span class="hljs-comment">// true</span>
<span class="hljs-comment">// true</span>
<span class="hljs-comment">// true</span>
</code></pre>
<p>&#x89E3;&#x51B3;&#x8FD9;&#x4E2A;&#x95EE;&#x9898;&#xFF0C;&#x4E5F;&#x662F;&#x901A;&#x8FC7;<code>bind</code>&#x65B9;&#x6CD5;&#x7ED1;&#x5B9A;<code>this</code>&#x3002;</p>
<pre><code class="lang-javascript">obj.print = <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) </span>{
  <span class="hljs-keyword">this</span>.times.forEach(<span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">n</span>) </span>{
    <span class="hljs-built_in">console</span>.log(<span class="hljs-keyword">this</span>.name);
  }.bind(<span class="hljs-keyword">this</span>));
};

obj.print()
<span class="hljs-comment">// &#x5F20;&#x4E09;</span>
<span class="hljs-comment">// &#x5F20;&#x4E09;</span>
<span class="hljs-comment">// &#x5F20;&#x4E09;</span>
</code></pre>
<p><strong>&#xFF08;3&#xFF09;&#x7ED3;&#x5408;<code>call</code>&#x65B9;&#x6CD5;&#x4F7F;&#x7528;</strong></p>
<p>&#x5229;&#x7528;<code>bind</code>&#x65B9;&#x6CD5;&#xFF0C;&#x53EF;&#x4EE5;&#x6539;&#x5199;&#x4E00;&#x4E9B; JavaScript &#x539F;&#x751F;&#x65B9;&#x6CD5;&#x7684;&#x4F7F;&#x7528;&#x5F62;&#x5F0F;&#xFF0C;&#x4EE5;&#x6570;&#x7EC4;&#x7684;<code>slice</code>&#x65B9;&#x6CD5;&#x4E3A;&#x4F8B;&#x3002;</p>
<pre><code class="lang-javascript">[<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>].slice(<span class="hljs-number">0</span>, <span class="hljs-number">1</span>) <span class="hljs-comment">// [1]</span>
<span class="hljs-comment">// &#x7B49;&#x540C;&#x4E8E;</span>
<span class="hljs-built_in">Array</span>.prototype.slice.call([<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>], <span class="hljs-number">0</span>, <span class="hljs-number">1</span>) <span class="hljs-comment">// [1]</span>
</code></pre>
<p>&#x4E0A;&#x9762;&#x7684;&#x4EE3;&#x7801;&#x4E2D;&#xFF0C;&#x6570;&#x7EC4;&#x7684;<code>slice</code>&#x65B9;&#x6CD5;&#x4ECE;<code>[1, 2, 3]</code>&#x91CC;&#x9762;&#xFF0C;&#x6309;&#x7167;&#x6307;&#x5B9A;&#x4F4D;&#x7F6E;&#x548C;&#x957F;&#x5EA6;&#x5207;&#x5206;&#x51FA;&#x53E6;&#x4E00;&#x4E2A;&#x6570;&#x7EC4;&#x3002;&#x8FD9;&#x6837;&#x505A;&#x7684;&#x672C;&#x8D28;&#x662F;&#x5728;<code>[1, 2, 3]</code>&#x4E0A;&#x9762;&#x8C03;&#x7528;<code>Array.prototype.slice</code>&#x65B9;&#x6CD5;&#xFF0C;&#x56E0;&#x6B64;&#x53EF;&#x4EE5;&#x7528;<code>call</code>&#x65B9;&#x6CD5;&#x8868;&#x8FBE;&#x8FD9;&#x4E2A;&#x8FC7;&#x7A0B;&#xFF0C;&#x5F97;&#x5230;&#x540C;&#x6837;&#x7684;&#x7ED3;&#x679C;&#x3002;</p>
<p><code>call</code>&#x65B9;&#x6CD5;&#x5B9E;&#x8D28;&#x4E0A;&#x662F;&#x8C03;&#x7528;<code>Function.prototype.call</code>&#x65B9;&#x6CD5;&#xFF0C;&#x56E0;&#x6B64;&#x4E0A;&#x9762;&#x7684;&#x8868;&#x8FBE;&#x5F0F;&#x53EF;&#x4EE5;&#x7528;<code>bind</code>&#x65B9;&#x6CD5;&#x6539;&#x5199;&#x3002;</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> slice = <span class="hljs-built_in">Function</span>.prototype.call.bind(<span class="hljs-built_in">Array</span>.prototype.slice);
slice([<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>], <span class="hljs-number">0</span>, <span class="hljs-number">1</span>) <span class="hljs-comment">// [1]</span>
</code></pre>
<p>&#x4E0A;&#x9762;&#x4EE3;&#x7801;&#x7684;&#x542B;&#x4E49;&#x5C31;&#x662F;&#xFF0C;&#x5C06;<code>Array.prototype.slice</code>&#x53D8;&#x6210;<code>Function.prototype.call</code>&#x65B9;&#x6CD5;&#x6240;&#x5728;&#x7684;&#x5BF9;&#x8C61;&#xFF0C;&#x8C03;&#x7528;&#x65F6;&#x5C31;&#x53D8;&#x6210;&#x4E86;<code>Array.prototype.slice.call</code>&#x3002;&#x7C7B;&#x4F3C;&#x7684;&#x5199;&#x6CD5;&#x8FD8;&#x53EF;&#x4EE5;&#x7528;&#x4E8E;&#x5176;&#x4ED6;&#x6570;&#x7EC4;&#x65B9;&#x6CD5;&#x3002;</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> push = <span class="hljs-built_in">Function</span>.prototype.call.bind(<span class="hljs-built_in">Array</span>.prototype.push);
<span class="hljs-keyword">var</span> pop = <span class="hljs-built_in">Function</span>.prototype.call.bind(<span class="hljs-built_in">Array</span>.prototype.pop);

<span class="hljs-keyword">var</span> a = [<span class="hljs-number">1</span> ,<span class="hljs-number">2</span> ,<span class="hljs-number">3</span>];
push(a, <span class="hljs-number">4</span>)
a <span class="hljs-comment">// [1, 2, 3, 4]</span>

pop(a)
a <span class="hljs-comment">// [1, 2, 3]</span>
</code></pre>
<p>&#x5982;&#x679C;&#x518D;&#x8FDB;&#x4E00;&#x6B65;&#xFF0C;&#x5C06;<code>Function.prototype.call</code>&#x65B9;&#x6CD5;&#x7ED1;&#x5B9A;&#x5230;<code>Function.prototype.bind</code>&#x5BF9;&#x8C61;&#xFF0C;&#x5C31;&#x610F;&#x5473;&#x7740;<code>bind</code>&#x7684;&#x8C03;&#x7528;&#x5F62;&#x5F0F;&#x4E5F;&#x53EF;&#x4EE5;&#x88AB;&#x6539;&#x5199;&#x3002;</p>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">f</span>(<span class="hljs-params"></span>) </span>{
  <span class="hljs-built_in">console</span>.log(<span class="hljs-keyword">this</span>.v);
}

<span class="hljs-keyword">var</span> o = { v: <span class="hljs-number">123</span> };
<span class="hljs-keyword">var</span> bind = <span class="hljs-built_in">Function</span>.prototype.call.bind(<span class="hljs-built_in">Function</span>.prototype.bind);
bind(f, o)() <span class="hljs-comment">// 123</span>
</code></pre>
<p>&#x4E0A;&#x9762;&#x4EE3;&#x7801;&#x7684;&#x542B;&#x4E49;&#x5C31;&#x662F;&#xFF0C;&#x5C06;<code>Function.prototype.bind</code>&#x65B9;&#x6CD5;&#x7ED1;&#x5B9A;&#x5728;<code>Function.prototype.call</code>&#x4E0A;&#x9762;&#xFF0C;&#x6240;&#x4EE5;<code>bind</code>&#x65B9;&#x6CD5;&#x5C31;&#x53EF;&#x4EE5;&#x76F4;&#x63A5;&#x4F7F;&#x7528;&#xFF0C;&#x4E0D;&#x9700;&#x8981;&#x5728;&#x51FD;&#x6570;&#x5B9E;&#x4F8B;&#x4E0A;&#x4F7F;&#x7528;&#x3002;</p>
<h2 id="&#x53C2;&#x8003;&#x94FE;&#x63A5;">&#x53C2;&#x8003;&#x94FE;&#x63A5;</h2>
<ul>
<li>Jonathan Creamer, <a href="http://tech.pro/tutorial/1192/avoiding-the-this-problem-in-javascript" target="_blank" rel="nofollow">Avoiding the &quot;this&quot; problem in JavaScript</a></li>
<li>Erik Kronberg, <a href="https://variadic.me/posts/2013-10-22-bind-call-and-apply-in-javascript.html" target="_blank" rel="nofollow">Bind, Call and Apply in JavaScript</a></li>
<li>Axel Rauschmayer, <a href="http://www.2ality.com/2014/05/this.html" target="_blank" rel="nofollow">JavaScript&#x2019;s this: how it works, where it can trip you up</a></li>
</ul>




<footer class="page-footer-ex"> <span class="page-footer-ex-copyright"> <a href="https://xiaobaiai.net" target="_blank" rel="nofollow">&#x5C0F;&#x767D;AI.&#x6613;&#x540D;</a>, &#x4F7F;&#x7528;<a href="https://creativecommons.org/licenses/by-sa/4.0/" target="_blank" rel="nofollow">&#x77E5;&#x8BC6;&#x5171;&#x4EAB; 4.0 &#x534F;&#x8BAE;&#x53D1;&#x5E03;</a>&#x53D1;&#x5E03; </span> &#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0; <span class="page-footer-ex-footer-update"> <i>&#x9875;&#x9762;&#x4FEE;&#x8BA2;&#x4E8E;&#xFF1A;</i> 2019-08-22 16:53:02 </span> </footer>
                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="new.html" class="navigation navigation-prev " aria-label="Previous page: 实例对象与 New 命令">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="prototype.html" class="navigation navigation-next " aria-label="Next page: 对象的继承">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"this 关键字","level":"1.7.2","depth":2,"next":{"title":"对象的继承","level":"1.7.3","depth":2,"path":"docs/oop/prototype.md","ref":"docs/oop/prototype.md","articles":[]},"previous":{"title":"实例对象与 New 命令","level":"1.7.1","depth":2,"path":"docs/oop/new.md","ref":"docs/oop/new.md","articles":[]},"dir":"ltr"},"config":{"plugins":["-sharing","chapter-fold","back-to-top-button","search-pro","sharing-plus","myseo","favicon","page-footer-ex","search-pro","livereload"],"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"chapter-fold":{},"livereload":{},"page-footer-ex":{"copyright":"<a href='https://xiaobaiai.net' target='_blank'>小白AI.易名</a>, 使用<a href='https://creativecommons.org/licenses/by-sa/4.0/' target='_blank'>知识共享 4.0 协议发布</a>发布","markdown":false,"update_format":"YYYY-MM-DD HH:mm:ss","update_label":"<i>页面修订于：</i>"},"search-pro":{},"search":{},"sharing-plus":{"qq":false,"all":["facebook","google","twitter","instapaper","linkedin","pocket","stumbleupon"],"douban":false,"facebook":true,"weibo":false,"instapaper":false,"whatsapp":false,"hatenaBookmark":false,"twitter":true,"messenger":false,"line":false,"vk":false,"pocket":true,"google":false,"viber":false,"stumbleupon":false,"qzone":false,"linkedin":false},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"myseo":{"description":"Javascript教程","keywords":"小白AI.易名,xiaobaiai.net,Javascript,入门,教程,博客","titlePrefix":"Javascript教程 - ","titleSuffix":" - 小白AI.易名"},"fontsettings":{"theme":"white","family":"sans","size":2},"highlight":{},"favicon":{"shortcut":"assets/images/favicon.ico","bookmark":"assets/images/favicon.ico","appleTouch":"assets/images/apple-touch-icon.png","appleTouchMore":{"120x120":"assets/images/apple-touch-icon-120x120.png","180x180":"assets/images/apple-touch-icon-180x180.png"}},"back-to-top-button":{},"sharing":{"qq":true,"all":["qq","qzone","twitter","weibo","linkedin"],"douban":false,"facebook":true,"weibo":true,"instapaper":false,"whatsapp":false,"hatenaBookmark":false,"twitter":false,"messenger":false,"line":false,"vk":false,"pocket":false,"google":false,"viber":false,"stumbleupon":false,"qzone":true,"linkedin":false},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"theme":"default","author":"小白AI.易名","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"language":"zh-hans","gitbook":"*","description":"Javascript教程"},"file":{"path":"docs/oop/this.md","mtime":"2019-08-22T08:53:02.359Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2019-08-28T05:00:46.673Z"},"basePath":"../..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../../gitbook/gitbook.js"></script>
    <script src="../../gitbook/theme.js"></script>
    
        
        <script src="../../gitbook/gitbook-plugin-chapter-fold/chapter-fold.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-back-to-top-button/plugin.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-search-pro/jquery.mark.min.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-search-pro/search.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-sharing-plus/buttons.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-livereload/plugin.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-search/search-engine.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-search/search.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

